A school is trying to take an annual photo of all students.
Students must stand in a single line in non-decreasing height order.
Let the correct order be array
expected, where expected[i] is the expected height of the i-th student.You are given an integer array
heights representing the current order of students.
heights[i] is the height of the i-th student in line.Return the number of indices
i where heights[i] != expected[i]Example 1
Input: heights = [5,1,2,3,4]
Output: 5
Explanation: After sorting [1,2,3,4,5] all positions differ — 5 people are out of place.
Output: 5
Explanation: After sorting [1,2,3,4,5] all positions differ — 5 people are out of place.
Example 2
Input: heights = [1,2,3,4,5]
Output: 0
Explanation: The array is already sorted — no one is out of place.
Output: 0
Explanation: The array is already sorted — no one is out of place.
Example 3
Input: heights = [1,1,4,2,1,3]
Output: 3
Explanation: Sort by height [1,1,1,2,3,4] and compare with the original — 3 mismatched positions.
Output: 3
Explanation: Sort by height [1,1,1,2,3,4] and compare with the original — 3 mismatched positions.