![]() |
VOOZH | about |
Given an array containing marks of students, the task is to calculate the percentile of the students. The percentile is calculated according to the following rule:
The percentile of a student is the % of the number of students having marks less than him/her.
Examples:
Input: arr[] = { 12, 60, 80, 71, 30 }
Output: { 0, 50, 100, 75, 25 }
Explanation:
Percentile of Student 1 = 0/4*100 = 0 (out of other 4 students no one has marks less than this student)
Percentile of Student 2 = 2/4*100 = 50 (out of other 4 students, 2 have marks less than this student)
Percentile of Student 3 = 4/4*100 = 100 (out of other 4 students, all 4 have marks less than this student)
Percentile of Student 4 = 3/4*100 = 75 (out of other 4 students, 3 have marks less than this student)
Percentile of Student 5 = 1/4*100 = 25 (out of other 4 students only 1 has marks less than this student)
Approach:
Below is the implementation of the above approach:
Percentile of Student 1 = 0 Percentile of Student 2 = 50 Percentile of Student 3 = 100 Percentile of Student 4 = 75 Percentile of Student 5 = 25
Time Complexity: O(n2)
Auxiliary Space: O(1)