Amazon Academy recently organized a scholaship test on its platform.
There are n
students with roll numbers 1, 2, ..., n
who appeared for the test, where the rank secured by the ith
student 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
x
in the range [1, n]
.
Notes
- 1. The mean value of an array of
k
elements is defined as the sum of elements divided byk
. - 2. A permutation of leangth
n
is a sequence where each number fromq
ton
appears exactly once. - 3. A subarray of an array is a contiguous section of the array.
Function Description
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 π ***
Example 1:

Input: rank = [1, 2, 3, 4, 5]
Output: [1, 2, 3, 2, 1]
Explanation:Read the above as 'For the mean x = 1, the group [1] has mean value 1. There is 1 group'. and so on. The full answer is [1, 2, 3, 2, 1].
Example 2:
Input: rank = [4, 3, 2, 1]
Output: [1, 2, 2, 1]
Explanation:x = 1 -> [1] x = 2 -> [3, 2, 1], [2] x = 3 -> [3], [4, 3, 2] x = 4 -> [4]
Example 3:
Input: rank = [4, 7, 3, 6, 5, 2, 1]
Output: [1, 1, 1, 4, 4, 1, 1]
Explanation:x = 1 -> [1] x = 2 -> [2] x = 3 -> [3] x = 4 -> [4], [3, 6, 5, 2], [7, 3, 6, 5, 2, 1], [4, 7, 3, 6, 5, 2 ,1] x = 5 -> [5], [7, 3], [4, 7, 3, 6] and [4, 7, 3, 6, 5] x = 6 -> [6] x = 7 -> [7]
- 1 <= n <= 103
- 1 <= rank[i] <= n
- The array rank contains all distinct elemens, and thus, is a permutation of {1..n}.

input:
output: