Given an array of heights, return how many indices are not in the position they would occupy after sorting the array in non-decreasing order. A counting-style approach works well when the value range is bounded.
heights = array of heights
number of indices that differ from sorted order
Example 1:
Input:
heights = [1,1,4,2,1,3]
Output:
3
Explanation:
Three positions differ from the sorted order [1,1,1,2,3,4].
Example 2:
Input:
heights = [5,1,2,3,4]
Output:
5
Explanation:
Every index differs from the sorted order.