Height Checker

Students stand in a line for a photo and should be arranged in non-decreasing order of height. `expected[i]` is the height the i-th student would have in that sorted line. Given the current line `heights`, return the number of indices where `heights[i] != expected[i]`.

30:00

Height Checker
easy
Free written solution
Topics
Companies

Students stand in a line for a photo and should be arranged in non-decreasing order of height. expected[i] is the height the i-th student would have in that sorted line. Given the current line heights, return the number of indices where heights[i] != expected[i].

Example 1:
Input: {"heights":[1,1,4,2,1,3]}
Output: 3
Constraints:
  • 1≤heights.length≤1001 \leq \text{heights.length} \leq 100

  • 1≤heights[i]≤1001 \leq \text{heights}[i] \leq 100

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"heights":[1,1,4,2,1,3]}

6 students stand in line. Count how many are not where a sorted line would put them.

the line for the photo

dashed = sorted height

in place

must move

1

1

4

2

1

3

0

1

2

3

4

5

height buckets (count left)

1 x0
2 x0
3 x0
4 x0

mismatches

0

Variables
VariableValue
n6
DepthFunction Call
Stack empty
0/15