Top Coding Interview Question – Solved

2 Live
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 currentlylstanding in their correct positions. Example height = [1, 1, 3, 3, 4, 1] 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. Function Description Complete the function countStudents in the editor below. countStudents has the following parameter(s): 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. Constraints Β· 1≀n≀ 105

Asked in: No companies listed

Image of the Question

Question Image Question Image

All Testcases Passed βœ”



Passcode Image

Solution


Please login to view the solution


Related Questions

| You are given a board of size M Γ— N where each cell can be either empty ('O') o… |
| Undirected Coloured Graph Shortest Path You are given an undirected weight… |
| Village Voyage A computer game "Village Voyage" has N villages (labeled 1 to… |
| Academic Decathlon Students are being selected for an academic decathlon tea… |
| Sum of Arrays Given two arrays each of length n, arr1 and arr2, in one opera… |
| Count Swaps During Custom Sorting Analyze the efficiency of the following so… |