FastPrepFastPrep
Problem Brief

Order Check (Backend)

INTERNOA

Students in a class are asked to stand in ascending order according to their heights for the annual class photograph. Determine the number of students not currently standing in their correct positions.

Function Description

Complete the function countStudents in the editor.

countStudents has the following parameter(s):

  1. int height[n]: an array of heights in the order the students are standing

Returns

int: the number of students not standing in the correct positions.

1Example 1

Input
height = [1, 1, 3, 3, 4, 1]
Output
3
Explanation
The 3 students indicated in red at indices 2, 4 and 5, are not in the right positions. The correct positions are [1, 1, 1, 3, 3, 4]. Return 3.

2Example 2

Input
height = [1, 1, 3, 4, 1]
Output
3
Explanation
The 3 students not standing in the correct position are at indices [2, 3, 4]. So, return 3. The currect positions are [1, 1, 1, 3, 4] :)

Constraints

Limits and guarantees your solution can rely on.

  • 1 ≤ n ≤ 105
  • 1 <= height[i] <= 109
public int countStudents(int[] height) {
  // write your code here
}
Input

height

[1, 1, 3, 3, 4, 1]

Output

3

Sign in to submit your solution.