Get Mean Rank Count π
Amazon Academy recently organized a scholaship test on its platform.
There are nstudents with roll numbers 1, 2, ..., n who appeared for the test, where the rank secured by the ithstudent is denoted
by rank[i]. Thus, the array rank is a permutation of length n. Groups can only be formed with students having consecutive roll numbers,
in other words, a subarray of the original array. For each value x (1 <= x <= n), find the number of groups that can be formed such that they have a
mean rank equal to x.
More formally, given a permutaion of length n, find the number of subarrays of the given array having a mean value equal to x, for each
xin the range [1, n].
Notes
- 1. The mean value of an array of
kelements is defined as the sum of elements divided byk. - 2. A permutation of leangth
nis a sequence where each number fromqtonappears exactly once. - 3. A subarray of an array is a contiguous section of the array.
Complete the function getMeanRankCount in the editor. getMeanRankCount has the
following parameter: int rank[n]: the ranks of the students.
Returns
int[n]: the ith integer (where 1 <= i <= n) denotes the number of groups with a mean rank of i.
*** Credit to precurewalker π ***
1Example 1

2Example 2
3Example 3
Constraints
Limits and guarantees your solution can rely on.