Skip to content
LC-1051 Easy LeetCode

1051. Height Checker

Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 81% Topics: Array, Sorting, Counting Sort
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(nlogn)
# Space: O(n)

import itertools


class Solution(object):
    def heightChecker(self, heights):
        """
        :type heights: List[int]
        :rtype: int
        """
        return sum(i != j for i, j in itertools.izip(heights, sorted(heights)))

Solution from kamyu104/LeetCode-Solutions · MIT