How Many Numbers Are Smaller Than the Current Number

Easy

For each element of nums, count how many other elements are strictly smaller than it and return those counts in the original order.

Example 1

smallerNumbersThanCurrent()
Input
nums = [8,1,2,2,3]
Output
[4,0,1,1,3]

Example 2

smallerNumbersThanCurrent()
Input
nums = [6,5,4,8]
Output
[2,1,0,3]
Constraints
2 <= nums.length <= 500
0 <= nums[i] <= 100

Topics

ArraysSortingHash Table

Implement smallerNumbersThanCurrent in the editor and return the answer — printing it is never graded.