Ugly Number II - Leetcode 264 - Python

preview_player
Показать описание


0:00 - Read the problem
0:30 - Heap Explanation
5:45 - Coding Heap Solution
7:27 - Array Explanation
12:54 - Coding Array Solution

leetcode 264

#neetcode #leetcode #python
Рекомендации по теме
Комментарии
Автор

To everyone grinding through LeetCode and questioning if they're good enough when comparing themselves to others' success—don't give up.

uyna
Автор

Once you know how to generate these numbers, problem seems trivial. But IDK how to build up the intuition to come up with the solution on my own.

ShinAkuma
Автор

Oh man, I thought i was doing okay coming up with that heap solution on my own, but your array solution is seriously next level. 😮

jamestwosheep
Автор

Leetcode is just like Jack Salter in Grand Turismo : "I am here to prove that you can't"

ramvishnu
Автор

The three pointers solution is so elegant.

ritikkhatri
Автор

what the heck was that man. i would have got the array solution even in my whole life

namandubey
Автор

Understood third solution, but I won't code that yet. Remind me to come back later, I will try to come up with that on my own.

srajanmishra
Автор

Initially i tried brute force solution but go TLE in the morning. Later i tried again and again i couldn't got one. I left and came back in afternoon tried again with fresh mindset then after some time i got the first approach using min heap. I thought i optimized but the solution is still not the best solution. Then i came to your video to find the optimized solution. But man how could we get such ideas.

Besides nice explanation.

chukkalasaiganadev
Автор

this problem waited for years for someone to make this one thanks

johnj
Автор

dont understand the intuition at all. I mean multiplying 1 by 2, 3, 5 and then all of the children of one with 2, 3, 5 makes sense but not sure how I would ve come to the conculsion to use min heaps and use the smallest. Maybe due to the lack of my graph knowledge...

sharoozasghar
Автор

neetcode stop seshing us, the dp solution is in O(n)! bro what do i do if google asks me to optimize the heap solution - i am cooked (this is half a joke)

VineetMarri
Автор

in your bruteforce solution, u can also dicard visited set instead take a set and push all the elements into it that way u dont have to keep track of visited elements

mahine_mein_google
Автор

This 3 pointer solution, is it some kind of pattern/known way of solving problem or just some constructive algo. especially for this problem??

shruti-raj
Автор

How I can come up to the solution without seen problem before !!?

IK-xkex
Автор

Thank you for the great video! The first heap solution makes sense to me. Can you further explain the definition of the three-pointers?

tianyu
Автор

Started to solve the problem thinking i got this. TLE got the best of me

Nischal.shetty
Автор

NeetCode Medium Question:
From starting to till now how many different intro is used by Navdeep if today's intro is "Hey, Everyone welcome back, and lets write some NeetCode".

Answer : 2, As on his first video he can't be saying Welcome Back coz everyone was coming for first time. (I don't know why I commented this...)

hasrat
Автор

Interesting problem. I've actually had more time for personal projects lately and I guess I forgot I was solving leetcode and trying to optimise for a real world situation where we'll need to make this check multiple times. Here's now I tried to optimise for multiple reads:

Seive of eratothenes (lol... )
I figured that as long as I have sufficiently large seive of eratothenes, I could make that sieve just once, take the performance penalty for creating that massive sieve and then going on to be rest assured that every lookup that for the nth ugliest number will take a 0(1) look up since the function that returns the sieve is cached. Of course in a real situation, we'd need to know the limits of n so that we'd know what's the sufficient size of the sieve to solve this problem.

I read the editorial and I still needed to watch your video to actually snap out of the production-code-optimisation bubble and context switch to leetcode level problems. Yikes. Another lesson in the bag; " Be kind on yourself and give your brain enough time to rest and gracefully context switch to something you take equally as serious as your job or open source projects "

Man, I'm

AND MOST IMPORTANTLY, thanks again for all that you do!

dera_ng
Автор

Still a year of daily grinding to go until I get my leetcode shirt 😆

deanwthompson
Автор

Every number is beautiful, there are no Ugly numbers.

anandsrikumar
welcome to shbcf.ru