Height Checker
EasyArrays & Hashinghashing
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Students line up for a photo in the order given by heights. The photographer wants them arranged in **non-decreasing** order of height.
Return the number of positions i where heights[i] differs from the height that would stand at position i in the sorted lineup.
Examples
Input: heights = [1,1,4,2,1,3]
Output: 3
Sorted is [1,1,1,2,3,4]; positions 2, 4 and 5 differ.
Input: heights = [5,1,2,3,4]
Output: 5
Sorted is [1,2,3,4,5]; every position differs.
Input: heights = [1,2,3,4,5]
Output: 0
Already sorted.
Constraints
- 1 <= heights.length <= 100
- 1 <= heights[i] <= 100
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.