0% completed
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.
Example 1:
[5, 1, 2, 3, 4, 8, 1]
3
[1, 1, 2, 3, 4, 5, 8]
. Comparing with heights
, the positions that do not match are 0, 5 and 6.Example 2:
[10, 6, 8, 5, 9]
3
[5, 6, 8, 9, 10]
. Comparing with heights
, the positions that do not match are 0, 3 and 4.Example 3:
[7, 3, 2, 1, 4]
5
[1, 2, 3, 4, 7]
. All positions differ from heights
.Constraints:
1 <= heights.length <= 100
1 <= heights[i] <= 100
Try solving this question here:
.....
.....
.....