Problem statement

https://leetcode.com/problems/height-checker/

Solution

Just check what is asked.

Complexity

It is O(n log n) for time and space.

Code

class Solution:
    def heightChecker(self, H):
        return sum(x != y for x, y in zip(H, sorted(H)))