class Solution: def smallerNumbersThanCurrent(self, nums: List[int]) -> List[int]: s = sorted(nums) d= {} for i in range(len(s)): if s[i] not in d: d[s[i]] = i return [d[i] for i in nums]
@Rednuz-882 жыл бұрын
What is the space complexity of this problem?
@Elfein2 жыл бұрын
O(n)
@kirtibhushan2 жыл бұрын
Thanks man!
@olabanji3 жыл бұрын
Thanks for the videos you make. They've all been helpful so far. Keep up the good work!
@KnowledgeMavens2 жыл бұрын
You're welcome, thank you for watching!
@rajeshseptember092 жыл бұрын
Clear explanation ! Thanks. Is it possible to solve this is O(N) time ? Using extra space ? I mean without using any sorting to achieving this !
@KnowledgeMavens2 жыл бұрын
Hey Rajesh, that's for watching and commenting. Great suggestion! Honestly, I didn't go further into this problem to consider a better space complexity given its small data set. However, it would be very beneficial to do so when implementing this algorithm on a larger set of data. Thanks again for the suggestion and I'll consider sharing more on this topic in the future.