You are given an array of student marks. Your task is to calculate the percentile for each student based on the following rule:
The percentile of a student is the percentage of students having marks strictly less than their own. The denominator for this calculation should be the total number of other students (N-1).
The formula is:
Percentile = floor( (Number of students with marks < current student's marks) * 100 / (N - 1) )
Your function should return an array containing the percentile for each student, corresponding to their original order in the input array.
Input Format:
The first line contains a single integer N, the number of students.
The second line contains N space-separated integers, representing the marks of each student.
Output Format:
Your function should return a list/array of integers representing the percentile of each student in the original order.
Note:
The calculation uses integer division, so any fractional part is truncated.
If N <= 1, a percentile is not well-defined. In this case, your function should handle it appropriately (e.g., return [0]).
An O(N^2) brute-force solution may be too slow. An O(N log N) solution using sorting is more efficient.