class Solution:
def smallerNumbersThanCurrent(self, nums: List[int]) -> List[int]:
# [1,2,2,3,8]
# [0,1,2,3,4]
sorted_nums = sorted(nums)
mapping = {}
for i, num in enumerate(sorted_nums):
if num not in mapping:
mapping[num] = i
return [mapping[num] for num in nums]
Sort the array. Then the procedure is trivial.