# 1365. How Many Numbers Are Smaller Than the Current Number

`class Solution:    def smallerNumbersThanCurrent(self, nums):        hashtable=dict()        for i in nums:            hashtable[i]=0        for i in nums:            for j in hashtable:                if(j>i):                    hashtable[j]+=1        for i in range(len(nums)):            nums[i]=hashtable[nums[i]]        return(nums)`
`#prefix sum of the counts array usedclass Solution:    def smallerNumbersThanCurrent(self, nums):        max_=max(nums)        counts = [0]*(max_+1)        for i in range(len(nums)):            counts[nums[i]]+=1        for i in range(1,max_+1):            counts[i]+=counts[i-1]        for i in range(len(nums)):            if(nums[i]==0):                nums[i]=0            else:                nums[i]=counts[nums[i]-1]        return nums        #Time O(n)    #Space O(1)    to save the space we store the final answer in to the same array`

--

--

--

## More from Dhanarajappu

Tech-Enthusiast, Coder,Explorer,Geeky,Software Engineer |A piece of code delivers everything that you need. The world is all about codes.

Love podcasts or audiobooks? Learn on the go with our new app.

## Dhanarajappu

Tech-Enthusiast, Coder,Explorer,Geeky,Software Engineer |A piece of code delivers everything that you need. The world is all about codes.