Toppers Of Class
Easy Accuracy: 65.61% Submissions: 285 Points: 2

There is a class of N students and the task is to find the top K marks scorers. You need to print the index of the toppers of the class which will be same as the index of the student in the input array (use 0-based indexing). First print the index of the students having highest marks then the students with second highest and so on. If there are more than one students having same marks then print their indices in ascending order.Suppose k = 2 and the students having highest marks have indices 0 and 5 and students having second highest marks have indices 6 and 7 then output will be 0 5 6 7.

Example 1:

N=5 K=3
arr[] = { 2, 2, 1, 3, 1 }
Output: 3 0 1
Explanation: Topper with 3 marks is present 
at 3rd index, 2 marks is present at 0th 
index and next at 1st index.

Example 2:

N=4 K=1
arr[] = { 1, 2, 3, 4 } 
Output: 3
Explanation: The highest marks is at index 3.

Your Task:
Since this is a function problem. You don't need to take any input, as it is already accomplished by the driver code. You just need to complete the function kTop() that takes array A and integer N as parameters and change the given array according to the given conditions. You do not have to return anything


Expected Time Complexity: O(NlogN).
Expected Auxiliary Space: O(1).


1 ≤ N ≤ 106
1 ≤ M ≤ 106

to report an issue on this page.


We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?


All Submissions

My Submissions:

Login to access your submissions.

Toppers Of Class

Output Window