Back to course home
0% completed
Vote For New Content
Height Checker (easy)
Problem Statement
A school is organizing its annual photo session, and students must stand in a single line arranged by height in non-decreasing order. The expected order of heights is represented by an array expected
, where expected[i]
is the height of the i<sup>th</sup> student in line.
Given an array heights
representing the current order in which students are standing, determine how many positions in the heights
array do not match the expected
order.
Examples
-
Example 1:
- Input: heights =
[5, 1, 2, 3, 4, 8, 1]
- Expected Output:
3
- Justification: The expected order is
[1, 1, 2, 3, 4, 5, 8]
. Comparing withheights
, the positions that do not match are 0, 5 and 6.
- Input: heights =
-
Example 2:
- Input: heights =
[10, 6, 8, 5, 9]
- Expected Output:
3
- Justification: The expected order is
[5, 6, 8, 9, 10]
. Comparing withheights
, the positions that do not match are 0, 3 and 4.
- Input: heights =
-
Example 3:
- Input: heights =
[7, 3, 2, 1, 4]
- Expected Output:
5
- Justification: The expected order is
[1, 2, 3, 4, 7]
. All positions differ fromheights
.
- Input: heights =
Constraints:
1 <= heights.length <= 100
1 <= heights[i] <= 100
Solution
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Like the course? Get enrolled and start learning!
Table of Contents
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible