INSERT INTO CIRCULAR LINKED LIST | LEETCODE # 708 | PYTHON SOLUTION

Sdílet
Vložit
  • čas přidán 24. 07. 2024
  • In this video we are solving a popular Facebook interview question: Insert Into Sorted Linked List (Leetcode # 708).
    The question isn't really that difficult but there are four cases you need to identify and handle in order to fully solve this question. Let's go through them and figure out how to code this.
    TIMESTAMPS:
    00:00 Intro
    00:15 Question Prompt
    01:05 Basic Example
    02:11 Solution Intuition
    07:25 Coding
    13:30 Time/Space Complexity
    15:00 Outro
  • Věda a technologie

Komentáře • 13

  • @aman4434
    @aman4434 Před 5 měsíci +6

    I would like to add that your code works, but you may have missed mentioning one case. For something like [3,4,1] and insert 2, our curr reaches 1 and then breaks as curr.next is now 3.
    However we haven't inserted anything yet.
    If we now add the new node in front of curr, it works! As you have done.
    But it is not only the case that we reach outside the loop on a univalued linked list. It is such a case as well. And in this case, it is necessary to add the new value right after curr, and not at any random point in the linked list!
    How I personally deal with this is by:
    curr = head
    flag = 1
    while curr != head or flag == 1:
    flag = 0

    • @ginotozzi7537
      @ginotozzi7537 Před 4 měsíci

      Good catch! I also noticed this and realized the last bit of logic catches this. But he misses that in the video like you said.

  • @manojamrutharaj9071
    @manojamrutharaj9071 Před rokem

    Awesome explanation covering all the cases. Thanks.
    This problem is somewhat different in which the node starting at head is the least valued node.

  • @landocodes
    @landocodes Před 5 měsíci +2

    I'm not sure if you're comfortable linking to your leetcode, or wanting to go an extra step, but it'd be nice if you could share the actual text of your code. NBD but sometimes the full code doesn't fit on your screen so it'd be a bit helpful.

  • @YT.Nikolay
    @YT.Nikolay Před rokem

    this problem really cracked my head :D Thanks for the explanation!

  • @matthewsaucedo2471
    @matthewsaucedo2471 Před 9 měsíci

    Awesome explanation!

  • @subee128
    @subee128 Před 5 měsíci

    Thank you very much

  • @landocodes
    @landocodes Před 5 měsíci

    Keep it up bro! I've begun moving from neetcode to this channel. Your solutions/videos are really straight forward.
    Do you plan on doing any system design videos at some point?

  • @AmolGautam
    @AmolGautam Před 7 měsíci

    Thank you

  • @Change510
    @Change510 Před rokem

    Thanks

  • @nithinsastrytellapuri291
    @nithinsastrytellapuri291 Před 5 měsíci

    Condition on line number 19 is very important

  • @gokulbalagopal9733
    @gokulbalagopal9733 Před 5 měsíci

    what if there is a case where we have a circular linked list like this: [3,3,4,] and we want to insert a 9. Shouldn't the 9 be inserted between 4 and the head (3). In such a case, I feel the code explained above may not work. If I have missed something please let me know. Thanks in advance, for your help.

    • @davidmwangi4312
      @davidmwangi4312 Před měsícem +1

      Its already covered on insert on the edge , case scenario.