Height Checker

Easy

The students in heights must stand in non-decreasing order. Return how many positions differ from the sorted order.

Example 1

heightChecker()
Input
heights = [1,1,4,2,1,3]
Output
3

Why

Sorted: [1,1,1,2,3,4] — indices 2, 4 and 5 differ.

Example 2

heightChecker()
Input
heights = [5,1,2,3,4]
Output
5
Constraints
1 <= heights.length <= 100
1 <= heights[i] <= 100

Topics

ArraysSorting

Implement heightChecker in the editor and return the answer — printing it is never graded.