Ugly Number II - Leetcode 264 - Python

Поделиться
HTML-код
  • Опубликовано: 9 ноя 2024

Комментарии • 47

  • @uyna208
    @uyna208 2 месяца назад +80

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

    • @chien-yucode992
      @chien-yucode992 2 месяца назад +1

    • @JamesBond-mq7pd
      @JamesBond-mq7pd 2 месяца назад +1

      💪💪

    • @mohit6215
      @mohit6215 2 месяца назад

      Thanks😅

    • @LoayAl-Said-j8p
      @LoayAl-Said-j8p 2 месяца назад

      Thank you brother,
      And if there is something i can add that would help so much,
      Learn How To Learn,
      Check a book and a course with the same name by Barbra Okley
      And a very small one on Edx called Learn Like A Pro
      And Trust me,
      in this world Defuse mode of your brain is your best friend

    • @freyappari
      @freyappari 2 месяца назад

      me irl

  • @ShinAkuma
    @ShinAkuma 2 месяца назад +16

    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.

    • @anomalyed
      @anomalyed 2 месяца назад +1

      The same problem I have. How do you build up the intuition to come up with how to generate these numbers?

  • @ritikkhatri
    @ritikkhatri 2 месяца назад +6

    The three pointers solution is so elegant.

  • @jamestwosheep
    @jamestwosheep 2 месяца назад +3

    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. 😮

  • @BikerInsights
    @BikerInsights 2 месяца назад +10

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

  • @johnj171
    @johnj171 2 месяца назад +4

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

  • @pratyushthakur8478
    @pratyushthakur8478 2 месяца назад +28

    this problem made me feel ugly

  • @namandubey8348
    @namandubey8348 2 месяца назад +4

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

  • @srajanmishra4587
    @srajanmishra4587 11 часов назад

    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.

  • @chukkalasaiganadev79
    @chukkalasaiganadev79 2 месяца назад +2

    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.

  • @tianyu9031
    @tianyu9031 2 месяца назад

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

  • @dera_ng
    @dera_ng 2 месяца назад +3

    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 tired😪.....
    AND MOST IMPORTANTLY, thanks again for all that you do!

  • @6mahine_mein_google
    @6mahine_mein_google 2 месяца назад

    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

  • @user-shruti-raj
    @user-shruti-raj 2 месяца назад +1

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

  • @longvu7746
    @longvu7746 2 месяца назад

    Great explanation

  • @hasrat17
    @hasrat17 2 месяца назад +3

    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...)

  • @Nischal.shetty02
    @Nischal.shetty02 2 месяца назад +1

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

    • @akarsan9121
      @akarsan9121 2 месяца назад

      what was your approach?

    • @Nischal.shetty02
      @Nischal.shetty02 2 месяца назад +1

      @@akarsan9121 very ugly brute force checking each element with prime numbers then pushing to ans array and returning last element

    • @akarsan9121
      @akarsan9121 2 месяца назад +2

      @@Nischal.shetty02 same actually, I thought of checking for combination of factors and then adding to list

  • @dmitrykarpenko2271
    @dmitrykarpenko2271 Месяц назад

    For the last solution - how to prove or illustrate that we need just three pointers?
    I.e.: we created the pointers only for the first ramification. When we get more subtrees, how do we know that we do not need to introduce more pointers to track more "racing" numbers? Why i2, i3, and i5 will always have the current minimum among them?

    • @dmitrykarpenko2271
      @dmitrykarpenko2271 Месяц назад

      After looking at the code - I think, a possible explanation can be: all i2, i3, and i5 are moving through ALL numbers calculated one by one, so they will exhaust all options

  • @anandsrikumar007
    @anandsrikumar007 2 месяца назад +1

    Every number is beautiful, there are no Ugly numbers.

  • @VineetMarri
    @VineetMarri 2 месяца назад +2

    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)

  • @sharoozasghar4956
    @sharoozasghar4956 2 месяца назад +2

    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...

  • @MP-ny3ep
    @MP-ny3ep 2 месяца назад +1

    Thank you !

  • @deanwthompson5633
    @deanwthompson5633 2 месяца назад +1

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

  • @yixinzhao7721
    @yixinzhao7721 2 месяца назад

    BFS with a Heap

  • @IK-xk7ex
    @IK-xk7ex 2 месяца назад +1

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

  • @selvaragavan_10
    @selvaragavan_10 2 месяца назад +1

    the second approach was not much intuitive ig.

    • @deepakjain4481
      @deepakjain4481 2 месяца назад

      i guess it becomes easy after you figure out graph and idea of a 3 pointer but that is still difficult

  • @bufdud4
    @bufdud4 2 месяца назад +1

    first

  • @zhenjieliang4680
    @zhenjieliang4680 2 месяца назад

    what. the.

  • @AnkitaNallana
    @AnkitaNallana 2 месяца назад

    First!

  • @sashrikgupta9708
    @sashrikgupta9708 2 месяца назад

    Mid