Description
A local inversion is A[i] > A[i+1]. A global inversion is A[i] > A[j] where i < j. Return true if the count of each is equal.
Examples
Input:
nums = [1,0,2]Output:
trueExplanation:
Both have 1 inversion.
Input:
nums = [1,2,0]Output:
falseExplanation:
For nums = [1,2,0], the answer is false because the global and local inversions condition is not met.
Input:
nums = [0,1,2,3]Output:
trueExplanation:
This array is already sorted, so there are no inversions at all. Both global inversions and local inversions equal 0, making the condition satisfied.
Constraints
- •
1 ≤ nums.length ≤ 10⁵