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`
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
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
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.
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`
Bro your explanation is very much fathomable than others. You give the best intuition about the problem.....
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.
First? wow, we stan neetcode, updated, finished my Uber interviews that I mentioned previous and went really well! Hopefully I get offer this month :)
Best of Luck !!!!
Posted challenge at 5.30...posted video at 6.40 dedication🔥👌
Hey babai brahmi Telugu ❤
Bramhi dp ❤
@@Md_sadiq_Md hello bro
@@jaisaichand6562 ❤️
@@Abdul_bablu naku telugu radu
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
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
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.
SOlved in first go ... thanks to neetcode videos
Hi, I really liked what neet code pro is doing, Do you have parity price adjustment for it as I simply cant afford it.
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 ??
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.
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
you are the goat
We don't even need line 20.
could be an easy imo.