How Many Numbers Are Smaller Than the Current Number

Problem Id: 1365 Difficulty: Easy Tag: Array Tag: Hash Table


Intuition

The length of the array is less than 500. So we could simple use brute force to solve this problem (Time Complexty: O(n*n)).

Solution


class Solution:
    def smallerNumbersThanCurrent(self, nums: List[int]) -> List[int]:
        return [len([num for num in nums if num < current]) for current in nums]