Split Linked List in Parts - Leetcode 725 - Python

แชร์
ฝัง
  • เผยแพร่เมื่อ 4 ม.ค. 2025

ความคิดเห็น • 22

  • @aynuayex
    @aynuayex ปีที่แล้ว +5

    i do not think we have to check if curr exists in the second loop, since it will always exist the edge case is where n < k well in that case it would not even get to the second loop , so with in the loop no need `if not curr: break`

  • @abid3801
    @abid3801 11 หลายเดือนก่อน +1

    Bro your explanation is very much fathomable than others. You give the best intuition about the problem.....

  • @santanu29
    @santanu29 ปีที่แล้ว +4

    I was able to code it on my own without looking at your video. Watching it now to see if there is a better way.

  • @peterdavidmora-stevens9185
    @peterdavidmora-stevens9185 ปีที่แล้ว +6

    First? wow, we stan neetcode, updated, finished my Uber interviews that I mentioned previous and went really well! Hopefully I get offer this month :)

    • @Rutu_More
      @Rutu_More ปีที่แล้ว

      Best of Luck !!!!

  • @Abdul_bablu
    @Abdul_bablu ปีที่แล้ว +17

    Posted challenge at 5.30...posted video at 6.40 dedication🔥👌

  • @jamesmnpl
    @jamesmnpl ปีที่แล้ว +2

    Thanks @neetcode. I and few of my friends liked the way you used to lay out the skeleton of the code as in like having the comments listed in order for each task and then filling in those sections with the code . Would love to see that , please do consider adding them it would be immensely helpful.
    Sorting a rotated array would be one such example from your past videos

  • @danielsun716
    @danielsun716 ปีที่แล้ว +1

    ef splitListToParts(self, head: Optional[ListNode], k: int) -> List[Optional[ListNode]]:
    total_length = 0
    node = head
    while node:
    total_length += 1
    node = node.next

    base_length = total_length // k
    remainder = total_length % k
    result = [None for _ in range(k)]
    i = 0
    cur = head
    while i < k and cur:
    result[i] = cur
    partial_size = base_length + (1 if i < remainder else 0)
    # already have the head in partial list
    for _ in range(partial_size - 1):
    cur = cur.next
    tmp = cur.next
    cur.next = None
    cur = tmp
    i += 1
    return result

  • @alexeyabramov8033
    @alexeyabramov8033 ปีที่แล้ว

    Great solution!!! Thanks for posting this. However, I doubt one could come up with such an optimized form on the interview without running the code though. A more explicit implementation is definitely doable.

  • @messi_codes
    @messi_codes ปีที่แล้ว +2

    SOlved in first go ... thanks to neetcode videos

  • @nofeah89
    @nofeah89 ปีที่แล้ว +1

    Hi, I really liked what neet code pro is doing, Do you have parity price adjustment for it as I simply cant afford it.

  • @AdityaRaj-xm6oi
    @AdityaRaj-xm6oi ปีที่แล้ว +1

    can anyone please explain to me how that inner loop is appending elements to sublists, when the append line is out of the inner loop ??

    • @swauce507
      @swauce507 ปีที่แล้ว

      it isnt appending elements, the way it works is that the head of each linked list group is being added to each sublist in res.

    • @rishitsaboo5979
      @rishitsaboo5979 4 หลายเดือนก่อน

      first "for' loop is appending head of partitions not whole linked list and
      second "for" loop is used for making partitions assigning Null to node

  • @abisheksaravanakumar745
    @abisheksaravanakumar745 ปีที่แล้ว

    you are the goat

  • @Ishtathuku
    @Ishtathuku 3 หลายเดือนก่อน

    We don't even need line 20.

  • @aazzrwadrf
    @aazzrwadrf ปีที่แล้ว +3

    could be an easy imo.