Height Checker
Easy · Array, Sorting, Counting Sort
A school is trying to take an annual photo of all the students. The students are asked to stand in a single file line in non-decreasing order by height. Let this ordering be represented by the integer array expected where expected[i] is the expected height of the ith student in line.
You are given an integer array heights representing the current order that the students are standing in. Each heights[i] is the height of the ith student in line (0-indexed).
Return the number of indices where heights[i] != expected[i].
Example 1
Input: heights = [1,1,4,2,1,3] Output: 3
heights: [1,1,4,2,1,3] expected: [1,1,1,2,3,4] Indices 2, 4, and 5 do not match.
Example 2
Input: heights = [5,1,2,3,4] Output: 5
heights: [5,1,2,3,4] expected: [1,2,3,4,5] All indices do not match.
Example 3
Input: heights = [1,2,3,4,5] Output: 0
heights: [1,2,3,4,5] expected: [1,2,3,4,5] All indices match.
Constraints
- 1 <= heights.length <= 100
- 1 <= heights[i] <= 100
Starter code (python)
class Solution(object):
def heightChecker(self, heights):
"""
:type heights: List[int]
:rtype: int
"""
Related problems
- Two Sum (Easy)
- Median of Two Sorted Arrays (Hard)
- Container With Most Water (Medium)
Previous: Last Substring in Lexicographical Order · Next: Previous Permutation With One Swap · All problems
Zepruv is a technical interview practice platform. Read any problem for free; sign in to run your code, submit and keep your progress.