ah, I really appreciate the intuition you applied here. I thought about sorting it & then applying a Map/Hashmap/Dictionary to track the occurrence of each digit in the nums Array & then loop through to get the final output so at best would be O(n log(n)) TC. Your SC is O(n) since you utilize an auxiliary smaller Array.
@MistaT442 жыл бұрын
For those wondering, look into counting sort to understand more on how this works. Cheers
@tanishktripathi87733 жыл бұрын
We can also use a hashmap Where we can put the key and their counts and we can have another function which could take an integer and a map as a parameter and that fucntion should return the count of the numbers smaller than the current argument passed and thus we can create another resultant array whose values can be filled by this function's outputs. Please let me know if this solution is upto the mark.
@megatronislive13313 жыл бұрын
loved it!! very well explained ;) i was struggling for days with other youtube solutions of this question but u did it in few mins .thnk you so much.
@xavierelon3 жыл бұрын
You’re welcome :)
@azeezpaloor12023 жыл бұрын
Great its really awesome and explained well. Thank you How to build the skill to identify proper solution for problems?
@adrianrooney47774 жыл бұрын
Clever solution, thanks for this
@roysantos53864 жыл бұрын
Thanks! The illustration really helped me understand the solution. I tried using a ternary operator rather than the if-else in the last for loop, it ends up being 1ms slower than using the if-else. I wonder why that is.
@xavierelon4 жыл бұрын
The runtime on leetcode has a lot to do with network connection so I wouldn’t look into a 1ms difference too much
@gatomas8053 жыл бұрын
Brilliant solution and explanation! Curious, how did you approach this problem or how do you approach any problem for that matter? Does it just come with a lot of practice and you see patterns? With this problem, I guess I automatically (which I need to break) went straight to 2 for loops (1 outer and an inside) which is obviously pathetically slower. This is of course, I haven't practice enough problems to add to my logic "toolbox" as some would say.
@xavierelon3 жыл бұрын
Hey man thanks really appreciate it. I definitely still have a longs way to go before I think I’m good but I try to figure out the problem on my iPad first, start with the brute force solution then try and improve it. You’ll start to recognize patterns over time and I try to use my intuition to figure out what data structure is best use case if I need one at all. The 2 for loops is fine but just see if you can improve it after you figure out the easy solution
@jhaganb92153 жыл бұрын
@@xavierelon i also had the same doubt , if possible can you upload a video about it like how to get solution from brute force approach to best time and space complexity one (any other sum)...
@wanyi87613 жыл бұрын
I like this solution A LOT thanks mate
@compncheese8358 Жыл бұрын
Thank you so much kind sir
@surajmaity61942 жыл бұрын
Thanks!
@akshaysolanki43403 жыл бұрын
Thanks for the great explanation. btw are you using ipad for drawing?
@xavierelon3 жыл бұрын
Yes I am
@stevefidarci53794 жыл бұрын
thanks
@xavierelon4 жыл бұрын
You’re welcome
@vaibhav95293 жыл бұрын
Why did you increment in the 5th line? Why is it required?
@xavierelon3 жыл бұрын
Pretty sure I explain in the video. It's been a while since I've looked at this one but pretty sure that I was just adding the nums array to a sequential array
@omtopale752 жыл бұрын
Why did you keep the length of the array as 101 why not 20 or any number for that matter
@nanug62924 жыл бұрын
class Solution { public int[] smallerNumbersThanCurrent(int[] nums) { int [] smaller = new int[101]; for(int i=0;i