Add Two Numbers | LeetCode 2 | Coding Interview Tutorial

Sdílet
Vložit
  • čas přidán 7. 09. 2024

Komentáře • 73

  • @TerribleWhiteboard
    @TerribleWhiteboard  Před 4 lety +19

    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!

    • @pleasesirmorevideos4684
      @pleasesirmorevideos4684 Před 4 lety +6

      leetcode dynamic programming medium and hards ones would be great

    • @TerribleWhiteboard
      @TerribleWhiteboard  Před 4 lety +8

      Planning on it.

    • @mohammedsanaullah1065
      @mohammedsanaullah1065 Před 4 lety

      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.

    • @RemyIcedOut
      @RemyIcedOut Před 4 lety +3

      Only small detail I'd add is briefly mentioning the big O/run time for the solutions you discuss.

    • @Ali-mc4le
      @Ali-mc4le Před 4 lety

      @@RemyIcedOut @Terrible Whiteboard Yes please! :)
      I know they will ask those in the interview and I will be lost haha

  • @ctcrnitv
    @ctcrnitv Před 2 lety +1

    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.

  • @srikarwarrior123
    @srikarwarrior123 Před 4 lety +15

    Thank you so much...LOve the way you explained..I mean so much detail..

  • @CSSoda
    @CSSoda Před 4 lety +14

    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

  • @kunal_chand
    @kunal_chand Před 4 lety +1

    The visual explanation side by side with the code is a brilliant idea to explain the conversion of your thoughts into code.

  • @andreiatrigueiro
    @andreiatrigueiro Před 3 lety +2

    Just to thank you your time for doing this VERY HELPFUL VIDEO!! :)

    • @andreiatrigueiro
      @andreiatrigueiro Před 3 lety

      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;
      }
      }

    • @TerribleWhiteboard
      @TerribleWhiteboard  Před 3 lety

      You're welcome!

  • @rushikeshbankar8250
    @rushikeshbankar8250 Před 4 lety +4

    damn im so glad i decided to click on this link from the discussion session

  • @6lack-Echo
    @6lack-Echo Před rokem

    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.

  • @joka2322
    @joka2322 Před 4 lety +6

    I love your videos man. They are explained very well. I wish I could give you 10k likes. Please keep making more videos!

  • @insaineyesay
    @insaineyesay Před 3 lety +2

    This was awesome. Helped me a ton. Thanks man!

  • @NicholasLeader0
    @NicholasLeader0 Před 3 lety +3

    I like the explanation, wishing this was in Python3 instead of JavaScript.
    Still a bunch of this whiteboarding is relevant to any language.

  • @Ww-ul8oe
    @Ww-ul8oe Před 2 lety

    Underrated channel. You are the best. Please upload more videos.

  • @andriitsarenko5545
    @andriitsarenko5545 Před 4 lety +5

    Thank you so much, this is a great explanation

  • @Shiva-zy7jq
    @Shiva-zy7jq Před 4 lety +8

    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.

  • @RemyIcedOut
    @RemyIcedOut Před 4 lety +6

    This is a great explanation, thanks!!

  • @bachollarishitej5375
    @bachollarishitej5375 Před 4 lety +5

    great job buddy!!!

  • @sandeepa4116
    @sandeepa4116 Před 3 lety

    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 :)

  • @chrashpun3818
    @chrashpun3818 Před 3 lety +2

    You did a great job explaining every step. Thank you!

  • @286432531
    @286432531 Před 4 lety +2

    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.

  • @iiju8212
    @iiju8212 Před rokem

    Visiting your channel after 2-3 years. Hope you are good.

  • @TheMastreano
    @TheMastreano Před 3 lety +2

    Bring on more content, great job!

  • @sourabh7718
    @sourabh7718 Před 3 lety

    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)

  • @Shiva-zy7jq
    @Shiva-zy7jq Před 4 lety +8

    You are the best :)

  • @brianyehvg
    @brianyehvg Před 3 lety

    super awesome vids man. hope you keep making more

  • @suri5023
    @suri5023 Před 3 lety

    thank you for helping us, newbies.

  • @AhmedKhaled72
    @AhmedKhaled72 Před 3 lety +2

    very good approach

  • @shootsir
    @shootsir Před 3 lety +1

    Why returning dummyHead.next gives the result? I don't see any assignment to the variable dummyHead.
    Sorry if my question sounds dumb.

  • @zeusruna
    @zeusruna Před 3 lety

    Nice explanation!

  • @yousefal-shinnawi3171
    @yousefal-shinnawi3171 Před 3 lety +1

    Yo, do you still post anymore? Your videos are amazing!

    • @TerribleWhiteboard
      @TerribleWhiteboard  Před 3 lety +2

      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.

    • @suhaibhussain1918
      @suhaibhussain1918 Před 2 lety

      @@TerribleWhiteboard Well then

  • @mattm1057
    @mattm1057 Před 3 lety

    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?

  • @cutliss
    @cutliss Před 3 lety

    Do you need those if statement to advance the nodes? The while loop seems to be already checking for the null

  • @AmmarRai
    @AmmarRai Před 3 lety +2

    Thatks for the great vid! btw, It's pronounced "mäjəˌlō" not "məˈdəlō"

  • @johnnm.8178
    @johnnm.8178 Před 4 lety +3

    I never thought of using an ipad as a whiteboard, which ipad do you use 11" or 12.9"?

  • @andrewcbuensalida
    @andrewcbuensalida Před 3 lety

    instead of modulo, could you just subtract 10?

  • @omertarikkoc3293
    @omertarikkoc3293 Před 3 lety +2

    Will you post new videos?

    • @TerribleWhiteboard
      @TerribleWhiteboard  Před 3 lety +2

      Eventually! I just need to find the time and inspiration. I have a lot going on right now.

  • @MrQuaex
    @MrQuaex Před 4 lety

    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

  • @haomiaoshi6670
    @haomiaoshi6670 Před 3 lety

    why return dummyhead.next? why it points to the whole LinkedList instead of one digit? why it suddenly returns three digits?

  • @piratevv
    @piratevv Před 3 lety +1

    which app do you use while explaining?

  • @Andrew0InsaneIsNucleus
    @Andrew0InsaneIsNucleus Před 3 lety +1

    which iPad is that?

  • @tatatabletennis
    @tatatabletennis Před 3 lety

    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

    • @Alphaantzz
      @Alphaantzz Před 3 lety

      He's adding the numbers from left to right which is backwards from the correct right to left approach.