FunctionRacerProblemsRace

Height Checker

BeginnerSorting and searchingPython, JavaScript, TypeScript, Java, C++

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

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Sorting and searching problems