diff --git a/1051-Height-Checker.py b/1051-Height-Checker.py new file mode 100644 index 0000000..3993ab1 --- /dev/null +++ b/1051-Height-Checker.py @@ -0,0 +1,29 @@ +''' +Students are asked to stand in non-decreasing order of heights for an annual photo. + +Return the minimum number of students that must move in order for all students to be standing in non-decreasing order of height. + + + +Example 1: + +Input: heights = [1,1,4,2,1,3] +Output: 3 + + + +Constraints: + + 1 <= heights.length <= 100 + 1 <= heights[i] <= 100 + + +''' +class Solution: + def heightChecker(self, heights: List[int]) -> int: + arr = sorted(heights) + res = 0 + for i in range(len(heights)): + if heights[i] != arr[i]: + res += 1 + return res