Build an integer array counts of the same length where counts[i] is the number of indices j > i with nums[j] < nums[i], that is, how many elements strictly smaller than nums[i] appear after it.
Return counts.
Examples
Example 1
Input: nums = [5, 2, 6, 1]
Output: [2, 1, 1, 0]
Explanation:
After 5 there are 2 smaller elements (2 and 1).
After 2 there is 1 smaller element (1).
After 6 there is 1 smaller element (1).
After 1 there are no smaller elements.
Example 2
Input: nums = [-1]
Output: [0]
Example 3
Input: nums = [-1, -1]
Output: [0, 0]
Explanation: Equal values do not count as smaller.
Constraints
1≤nums.length≤105
−104≤nums[i]≤104
Examples
Example 1
Input
nums = [5, 2, 6, 1]
Output
[2, 1, 1, 0]
Example 2
Input
nums = [-1]
Output
[0]
Example 3
Input
nums = [-1, -1]
Output
[0, 0]
Loading editor...
Run checks the sample cases; Submit runs every case.
Samples 3
Custom 0
passedwrong answertime limiterrorran, no expected valuenot run