LeetCode 1365 | How Many Numbers are Smaller than Current Number | Algorithm Explained (Java)

  Рет қаралды 11,449

Xavier Elon

Xavier Elon

Күн бұрын

Пікірлер: 30
@raysdev
@raysdev 3 жыл бұрын
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.
@MistaT44
@MistaT44 2 жыл бұрын
For those wondering, look into counting sort to understand more on how this works. Cheers
@tanishktripathi8773
@tanishktripathi8773 3 жыл бұрын
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.
@megatronislive1331
@megatronislive1331 3 жыл бұрын
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.
@xavierelon
@xavierelon 3 жыл бұрын
You’re welcome :)
@azeezpaloor1202
@azeezpaloor1202 3 жыл бұрын
Great its really awesome and explained well. Thank you How to build the skill to identify proper solution for problems?
@adrianrooney4777
@adrianrooney4777 4 жыл бұрын
Clever solution, thanks for this
@roysantos5386
@roysantos5386 4 жыл бұрын
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.
@xavierelon
@xavierelon 4 жыл бұрын
The runtime on leetcode has a lot to do with network connection so I wouldn’t look into a 1ms difference too much
@gatomas805
@gatomas805 3 жыл бұрын
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.
@xavierelon
@xavierelon 3 жыл бұрын
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
@jhaganb9215
@jhaganb9215 3 жыл бұрын
@@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)...
@wanyi8761
@wanyi8761 3 жыл бұрын
I like this solution A LOT thanks mate
@compncheese8358
@compncheese8358 Жыл бұрын
Thank you so much kind sir
@surajmaity6194
@surajmaity6194 2 жыл бұрын
Thanks!
@akshaysolanki4340
@akshaysolanki4340 3 жыл бұрын
Thanks for the great explanation. btw are you using ipad for drawing?
@xavierelon
@xavierelon 3 жыл бұрын
Yes I am
@stevefidarci5379
@stevefidarci5379 4 жыл бұрын
thanks
@xavierelon
@xavierelon 4 жыл бұрын
You’re welcome
@vaibhav9529
@vaibhav9529 3 жыл бұрын
Why did you increment in the 5th line? Why is it required?
@xavierelon
@xavierelon 3 жыл бұрын
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
@omtopale75
@omtopale75 2 жыл бұрын
Why did you keep the length of the array as 101 why not 20 or any number for that matter
@nanug6292
@nanug6292 4 жыл бұрын
class Solution { public int[] smallerNumbersThanCurrent(int[] nums) { int [] smaller = new int[101]; for(int i=0;i
@xavierelon
@xavierelon 4 жыл бұрын
It’s position-1 not i-1
@HemantSoni80555
@HemantSoni80555 3 жыл бұрын
Which note application you are using.
@xavierelon
@xavierelon 3 жыл бұрын
Good notes 4
@sanketsaitawdekar4440
@sanketsaitawdekar4440 Жыл бұрын
I lost you at 3:26.
@nanug6292
@nanug6292 4 жыл бұрын
thanks
@anupamsingh8925
@anupamsingh8925 4 жыл бұрын
chl bhtnike
I Solved 1583 Leetcode Questions  Here's What I Learned
20:37
ThePrimeTime
Рет қаралды 727 М.
СКОЛЬКО ПАЛЬЦЕВ ТУТ?
00:16
Masomka
Рет қаралды 2,7 МЛН
Человек паук уже не тот
00:32
Miracle
Рет қаралды 4,2 МЛН
PRANK😂 rate Mark’s kick 1-10 🤕
00:14
Diana Belitskay
Рет қаралды 11 МЛН
The Unfair Way I Got Good At LeetCode
23:02
Aman Manazir
Рет қаралды 97 М.
The Downsides Of C++ | Prime Reacts
21:23
ThePrimeTime
Рет қаралды 143 М.
Google Coding Interview With A High School Student
57:24
Clément Mihailescu
Рет қаралды 4,2 МЛН
How I would learn Leetcode if I could start over
18:03
NeetCodeIO
Рет қаралды 674 М.
10 years of coding in 13 minutes
13:28
Joma Tech
Рет қаралды 4,9 МЛН
How Many Numbers Are Smaller Than the Current Number | Leetcode - 1365
6:16
Algorithms Made Easy
Рет қаралды 2,9 М.
Object-Oriented Programming is Embarrassing: 4 Short Examples
28:03
Brian Will
Рет қаралды 2,1 МЛН