Scores of N students in an exam are given and asked to find top two scores of the students.
The question can be simply solved by sorting the array and printing elements from the last two indices.
Time complexity - O(NlogN) , where N is the size of the array
It can also be solved by iterating over all the elements of the array by keeping track of two maximum numbers of the array.
Time complexity - O(N) , where N is the size of the array
AUTHOR’S AND TESTER’S SOLUTIONS:
Author’s solution can be found here.
Tester’s solution can be found here.