Leetcode 1482 Solution
This article provides solution to leetcode question 1482 (how-many-numbers-are-smaller-than-the-current-number)
Access this page by simply typing in "lcs 1482" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/how-many-numbers-are-smaller-than-the-current-number
Solution
class Solution:
def smallerNumbersThanCurrent(self, nums: List[int]) -> List[int]:
a = [(num, i) for i, num in enumerate(nums)]
a.sort()
ans = [0] * len(nums)
for num, i in a:
l = 0
r = len(a) - 1
while l < r:
m = (l + r) // 2
if a[m][0] >= num:
r = m
else:
l = m + 1
ans[i] = l
return ans