Leetcode 790 Solution

This article provides solution to leetcode question 790 (global-and-local-inversions)

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

Solution

class Solution:
    def isIdealPermutation(self, A: List[int]) -> bool:
        return not any(1 for i, a in enumerate(A) if abs(a - i) > 1)