Tap here to switch tabs
Problem
Submissions

Problem: Global and Local Inversions

med
30 min
Try to solve the Global and Local Inversions problem.

Statement

You are given an integer array nums of length n which represents a permutation of all integers in the range [0,n−1][0, n - 1].

The number of global inversions is the total number of pairs (i,j)(i, j) satisfying:

  • 0≤i<j<n0 \leq i < j < n

  • nums[i] >> nums[j]

The number of local inversions is the total number of indices i satisfying:

  • 0≤i<n−10 \leq i < n - 1

  • nums[i] >> nums[i + 1]

Return true if the number of global inversions equals the number of local inversions, or false otherwise.

Constraints:

  • n ==== nums.length

  • 1≤n≤1051 \leq n \leq 10^5

  • 0≤0 \leq nums[i] <n< n

  • All integers in nums are unique.

  • nums is a permutation of all integers in the range [0,n−1][0, n - 1].

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Global and Local Inversions

med
30 min
Try to solve the Global and Local Inversions problem.

Statement

You are given an integer array nums of length n which represents a permutation of all integers in the range [0,n−1][0, n - 1].

The number of global inversions is the total number of pairs (i,j)(i, j) satisfying:

  • 0≤i<j<n0 \leq i < j < n

  • nums[i] >> nums[j]

The number of local inversions is the total number of indices i satisfying:

  • 0≤i<n−10 \leq i < n - 1

  • nums[i] >> nums[i + 1]

Return true if the number of global inversions equals the number of local inversions, or false otherwise.

Constraints:

  • n ==== nums.length

  • 1≤n≤1051 \leq n \leq 10^5

  • 0≤0 \leq nums[i] <n< n

  • All integers in nums are unique.

  • nums is a permutation of all integers in the range [0,n−1][0, n - 1].