We’re preparing your current view and syncing the latest data.
You are given an integer array nums. For each element nums[i], count the number of elements to the right of nums[i] that are smaller than nums[i] and return the counts as an array.
Example: Input: [5,2,6,1] Output: [2,1,1,0] Explanation: To the right of 5 there are 2 smaller elements (2 and 1). To the right of 2 there is only 1 smaller element (1). To the right of 6 there is 1 smaller element (1). To the right of 1 there is 0 smaller element.
An integer array nums.
An integer array counts where counts[i] is the count of smaller numbers to the right of nums[i].
1 <= nums.length <= 10^5 -10^4 <= nums[i] <= 10^4
Example 1
Input
[5,2,6,1]
Output
[2,1,1,0]
Explanation
For 5, smaller elements to right: 2,1 (count=2). For 2, smaller element to right: 1 (count=1). For 6, smaller element to right: 1 (count=1). For 1, no smaller element to right (count=0).