Height Checker
Students stand in a line with the given heights. The teacher wants them in non-decreasing order of height.
Return how many students are not standing at the position they would have in the sorted line. Do not change heights.
Example 1
heights [1,1,4,2,1,3]
returns 3
Sorted is [1, 1, 1, 2, 3, 4]; positions 2, 4 and 5 differ, so 3.
Example 2
heights [1,2,3]
returns 0
Already sorted: 0.
Constraints
1 <= len(heights) <= 1001 <= heights[i] <= 100
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Sorting and searching problems
- Kth Largest ElementBeginner
- Kth Smallest Distinct ValueBeginner
- Maximum Product of Two ElementsBeginner
- Median of the ListBeginner
- Names in OrderBeginner
- Shortest Words FirstBeginner
- Sort by Last DigitBeginner
- Strictly Increasing CheckBeginner