Linked List Cycle - Leetcode 141 - Linked Lists (Python)

Поділитися
Вставка
  • Опубліковано 16 гру 2024

КОМЕНТАРІ • 19

  • @GregHogg
    @GregHogg  4 місяці тому +1

    Master Data Structures & Algorithms For FREE at AlgoMap.io!

  • @anna-plink
    @anna-plink 4 місяці тому +6

    Great explanation for slow and fast pointers 👍 My solution to this problem was to reassign each node's value to 'seen'. And if I come up to a node that has value 'seen', then it must be in a loop

    • @GregHogg
      @GregHogg  4 місяці тому

      That's actually a great idea

  • @yvettcodes
    @yvettcodes Місяць тому

    I was solving this problem in the wrong way, but today I've learned about slow and fast pointers and how to use them. Thanks! Another successful solution :)

  • @praneetkomandur6576
    @praneetkomandur6576 5 місяців тому +3

    better than neetcode I cant even lie

  • @tobinjoseph5469
    @tobinjoseph5469 2 місяці тому +1

    you and and neetcode should collab !

  • @DMcDy
    @DMcDy 3 місяці тому

    Hi Greg! I'm just curious why create a dummy node at all? It seems like it works fine to just omit that and make slow = fast = head. Thanks for the video!

  • @chandrakanthVenisetty
    @chandrakanthVenisetty 7 місяців тому

    Great explanantion, really liking it so far. Concise solutions.
    Coming to this solution, I dont think we need to add a dummy node and start iterating from there, because as per Floyd's algo, they would eventually meet.
    In the example above, fast and slow would meet in second loop iteration, it's just more computation that's all. Let me know your thoughts.

  • @praneetkomandur6576
    @praneetkomandur6576 5 місяців тому +1

    Can I ask you something Greg. Are we supposed to think of solutions like this without tutorials? I find that humanly possible. I feel like im memorizing blind75 with understanding aswell but Im not sure if I'd be able to do any other problems (unless they're easy hashmap ones) Am I cooked for interviews or will the interviews most likely have blind75 type problems

    • @GregHogg
      @GregHogg  5 місяців тому +3

      It's okay to memorize for a while, often the blind 75 teaches new important algorithms that you wouldn't come up with on your own

    • @Infinitely16
      @Infinitely16 3 місяці тому +2

      It's just the situation that tech interviews are at, and it will just keep getting worse unfortunately. It is of course not valid, fair, or correct to expect someone to come up with this solution within 45 minutes (or less, depending on if there are follow-ups). No one in the world would be able to do it. This algorithm was devised by a computer science researcher and has a mathematical proof. So the absolute, only possible way to use this as a solution, is to have seen and practiced it before. So it's just a question of "hey have you seen this specific question before?"

  • @yingxie9974
    @yingxie9974 3 дні тому

    awesome !

    • @yingxie9974
      @yingxie9974 3 дні тому

      very good explanation ! Thanks !

  • @theSuitCat
    @theSuitCat 9 місяців тому +2

    Hey greg, was it always that easy for you to solve these problems ?
    I find it very difficult not to understan but to solve it on my own.
    btw your explanation is very good keep it up.

    • @GregHogg
      @GregHogg  9 місяців тому +2

      Lol definitely not easy at first, don't worry:)

  • @bthulasikrishna9597
    @bthulasikrishna9597 4 місяці тому

    Why it has O(n) time complex ?

  • @staywithmeforever
    @staywithmeforever 9 місяців тому

    Great explanation

    • @GregHogg
      @GregHogg  9 місяців тому

      Thank you so much :)