Skip to content

Practice Global and Local Inversions

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#775
LeetCode Problem

Global and Local Inversions

Problem Statement

nums is a permutation of 0 through n - 1. A global inversion is a pair i < j with nums[i] > nums[j]. A local inversion is an adjacent pair i, i + 1 with nums[i] > nums[i + 1]. Return whether the numbers of global and local inversions are equal.

Source: Global and Local Inversions on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [1,0,2]
Output
true

# Example 2

Input
nums = [1,2,0]
Output
false

Constraints

n == nums.length
1 <= n <= 10^5
0 <= nums[i] < n
All the integers of nums are unique.
nums is a permutation of all the numbers in the range [0, n - 1].

Related LeetCode Problems

Practice more problems similar to Global and Local Inversions.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.