Hey @terrible whiteboard great explanation, nicely done. I was wondering if we could directly store values in the second list rather than a dummy list. And if there was to be a complete carry over we could add another node to the second list and store the carry in it. finally returning the second list.
Hello Mate! Thanks for helping the community.I just found your channel ( from your comment on a leetcode post) I like your videos! Could you make a video on MUST-DO interview problems for FAANG/ Microsoft and other companies? That would be extremely helpful! Thanks
btw, sharing my solution (in Java) in case it is helpful for someone :) class Solution { public ListNode addTwoNumbers(ListNode l1, ListNode l2) { ListNode head = new ListNode(0); ListNode current = head; int carryValue = 0, result = 0, x = 0, y = 0; while (l1 != null || l2 != null){ x = (l1 != null) ? l1.val : 0; y = (l2 != null) ? l2.val : 0; result = x + y + carryValue; if ((result) > 9){ result -=10; current.next = new ListNode(result); current = current.next; carryValue = 1; }else{ current.next = new ListNode(result); current = current.next; carryValue = 0; } if (l1 != null) l1 = l1.next; if (l2 != null) l2 = l2.next; if (l1 == null && l2 == null) current.next = (carryValue == 1) ? new ListNode(carryValue) : null; } return head.next; } }
Have some of the best explaination on CZcams rlly learned a lot, you should post more man would love a watch a whole DS&A playlist by you and the way you explain things with the drawings! cheers.
Thank you very much for the explanation. You explain everything very patiently. I already subscribed and will be looking to learn a lot more from your videos. Hopefully your channel will grow and make profits.
Hey thank you for the video. Can you explain to me, a real dummy, why updating current.next also updates dummyHead?? If they occupy they same space in memory then why are they not equal? And why do we return dummyHead.next instead of dummyHead?
Can someone tell me how dummyHead changed from its initialisation to final return statement as required output We are not changing the dummy Head anywhere in the code Can anyone help me here
If there are any videos you'd like me to make or if you have any ideas on how to optimize this solution, let me know!
leetcode dynamic programming medium and hards ones would be great
Planning on it.
Hey @terrible whiteboard great explanation, nicely done. I was wondering if we could directly store values in the second list rather than a dummy list. And if there was to be a complete carry over we could add another node to the second list and store the carry in it. finally returning the second list.
Only small detail I'd add is briefly mentioning the big O/run time for the solutions you discuss.
@@RemyIcedOut @Terrible Whiteboard Yes please! :)
I know they will ask those in the interview and I will be lost haha
Looks like you don't post anymore but videos were some of the best on yt. I'll learn as much as I can from them.
Thank you so much...LOve the way you explained..I mean so much detail..
Thanks!
Hello Mate! Thanks for helping the community.I just found your channel ( from your comment on a leetcode post) I like your videos! Could you make a video on MUST-DO interview problems for FAANG/ Microsoft and other companies? That would be extremely helpful! Thanks
The visual explanation side by side with the code is a brilliant idea to explain the conversion of your thoughts into code.
Thanks!
Just to thank you your time for doing this VERY HELPFUL VIDEO!! :)
btw, sharing my solution (in Java) in case it is helpful for someone :)
class Solution {
public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
ListNode head = new ListNode(0);
ListNode current = head;
int carryValue = 0, result = 0, x = 0, y = 0;
while (l1 != null || l2 != null){
x = (l1 != null) ? l1.val : 0;
y = (l2 != null) ? l2.val : 0;
result = x + y + carryValue;
if ((result) > 9){
result -=10;
current.next = new ListNode(result);
current = current.next;
carryValue = 1;
}else{
current.next = new ListNode(result);
current = current.next;
carryValue = 0;
}
if (l1 != null)
l1 = l1.next;
if (l2 != null)
l2 = l2.next;
if (l1 == null && l2 == null)
current.next = (carryValue == 1) ? new ListNode(carryValue) : null;
}
return head.next;
}
}
You're welcome!
damn im so glad i decided to click on this link from the discussion session
Haha. Thanks.
Have some of the best explaination on CZcams rlly learned a lot, you should post more man would love a watch a whole DS&A playlist by you and the way you explain things with the drawings! cheers.
I love your videos man. They are explained very well. I wish I could give you 10k likes. Please keep making more videos!
Thanks! Will do.
This was awesome. Helped me a ton. Thanks man!
You're welcome!
I like the explanation, wishing this was in Python3 instead of JavaScript.
Still a bunch of this whiteboarding is relevant to any language.
Cool. Thanks!
Underrated channel. You are the best. Please upload more videos.
Thank you so much, this is a great explanation
Thank you!
Hi. I wanted to let you know that you are videos are really helpful. The iPad drawing explanation is really helpful. Please do more leetcode videos.
Will do!
@@TerribleWhiteboard Thank you :-)
This is a great explanation, thanks!!
Thanks!
great job buddy!!!
Thanks!
This is the best ever explanation I could get so far. For any problem, I first search if you've explained it. Thanks a lot :)
You did a great job explaining every step. Thank you!
Thanks!
Thank you very much for the explanation. You explain everything very patiently. I already subscribed and will be looking to learn a lot more from your videos. Hopefully your channel will grow and make profits.
Thanks!
Visiting your channel after 2-3 years. Hope you are good.
Bring on more content, great job!
Thanks!
Good job. At 20:20 when you check if carry exist you added 1 to the node, it should be current.next = new ListNode(carry)
You are the best :)
Thanks!
super awesome vids man. hope you keep making more
thank you for helping us, newbies.
very good approach
Thanks!
Why returning dummyHead.next gives the result? I don't see any assignment to the variable dummyHead.
Sorry if my question sounds dumb.
Nice explanation!
Yo, do you still post anymore? Your videos are amazing!
Thanks! I'll be back this year for sure. I don't want to say when and then break my promise, but definitely this year.
@@TerribleWhiteboard Well then
Hey thank you for the video. Can you explain to me, a real dummy, why updating current.next also updates dummyHead?? If they occupy they same space in memory then why are they not equal? And why do we return dummyHead.next instead of dummyHead?
Do you need those if statement to advance the nodes? The while loop seems to be already checking for the null
Thatks for the great vid! btw, It's pronounced "mäjəˌlō" not "məˈdəlō"
Got it. Thanks!
I never thought of using an ipad as a whiteboard, which ipad do you use 11" or 12.9"?
It's the 6th gen, so it's only 9.7".
instead of modulo, could you just subtract 10?
Will you post new videos?
Eventually! I just need to find the time and inspiration. I have a lot going on right now.
what is the reason for allocating p1 and p2? we dont care about l1 and l2 as we go, so we can just iterate thru them
why return dummyhead.next? why it points to the whole LinkedList instead of one digit? why it suddenly returns three digits?
which app do you use while explaining?
It's the Notes app on the iPad.
which iPad is that?
Just the regular 6th gen.
Can someone tell me how dummyHead changed from its initialisation to final return statement as required output
We are not changing the dummy Head anywhere in the code
Can anyone help me here
He's adding the numbers from left to right which is backwards from the correct right to left approach.