https://leetcode.com/problems/global-and-local-inversions/description/

I'd like to share a solution for a generous case, where `A`

is an arbitrary array. The time complexity is O(NlogN).

```
class Solution:
def isIdealPermutation(self, A):
"""
:type A: List[int]
:rtype: bool
"""
def find_local(A):
cnt = 0;
for i,j in zip(A[:],A[1:]):
if j < i:
cnt += 1
return cnt
def find_global(A):
cnt = 0;
l = []
for i in A:
x = bisect.bisect_right(l, i)
cnt += len(l) - x
bisect.insort(l, i)
return cnt
return find_local(A) == find_global(A)
```