How Many Numbers Are Smaller Than the Current Number
Given the array nums, for each nums[i], find out how many numbers in the array are smaller than it. That is, for each nums[i], count the number of valid j values such that j != i and nums[j] < nums[i].
Return the answer in an array.
Example 1
Input
nums = [8,1,2,2,3]Output
[4,0,1,1,3]For each element, the counts of smaller numbers are 4 for 8, 0 for 1, 1 for each 2, and 3 for 3.
Example 2
Input
nums = [6,5,4,8]Output
[2,1,0,3]For 6 there are two smaller numbers, for 5 there is one, for 4 there are none, and for 8 there are three.
Constraints
- 2 <= nums.length <= 500
- 0 <= nums[i] <= 100