Add Two Numbers Given as LinkedLists | Amazon | Microsoft | Facebook | Qualcomm

Поділитися
Вставка
  • Опубліковано 20 січ 2025

КОМЕНТАРІ • 230

  • @takeUforward
    @takeUforward  4 роки тому +57

    Understooooooooooooooood?
    .
    Instagram(connect if you want to know how a SDE's normal life is): instagram.com/striver_79/
    .
    .
    If you appreciate the channel's work, you can join the family: bit.ly/joinFamily

    • @elements8630
      @elements8630 3 роки тому

      understoood thanks

    • @harshitrathi3077
      @harshitrathi3077 3 роки тому

      Yea

    • @amishasahu1586
      @amishasahu1586 2 роки тому

      Understooooooooooooooooooood!!

    • @sunnykumarpal9679
      @sunnykumarpal9679 2 роки тому

      Thank you bhaiya for making such videos . which ever topic i feel hard i try to find your videos. Your videos are really fabulous . Please be making such videos.

  • @ankitr2969
    @ankitr2969 3 роки тому +140

    that's the tip, don't let interviewer know that u have already solved the problem. 😂

  • @GeekyBaller
    @GeekyBaller 4 роки тому +204

    I was asked this question in my interview with Amazon.
    Great work, Raj bhaiya!

    • @shivamverma9447
      @shivamverma9447 4 роки тому +3

      Hi, can you help me

    • @dutt_2302
      @dutt_2302 4 роки тому +19

      this problem can be solved without any create new node.
      O(1) - space complexity

    • @trmpsanjay
      @trmpsanjay 4 роки тому +3

      @@dutt_2302 yes by creating two pointer head and tail method

    • @muktadirkhan6674
      @muktadirkhan6674 3 роки тому +6

      @@dutt_2302 ​ You would have to create a single node if the carry is there at the last node. And btw the solution Striver explained is also O(1). The space isnt counted for the variables we need to return.

    • @muktadirkhan6674
      @muktadirkhan6674 3 роки тому +1

      @@trmpsanjay Its a singly linked list, what are you going to achieve by a tail pointer?

  • @avishekroy1642
    @avishekroy1642 3 роки тому +11

    your way of teaching is very simple, and easy to understand

  • @mrinmoyaus761
    @mrinmoyaus761 4 роки тому +16

    Great placement series is hitting bro just watching everytime i open youtube.

  • @abhay9994
    @abhay9994 Рік тому +2

    I wanted to send you a heartfelt thank you for your tireless dedication to teaching DSA for free. Your selflessness and passion for helping students with their job interview preparation have made a significant impact on my life and countless others. I am incredibly grateful for the knowledge and confidence you have imparted to us. Thank you for everything you do!❣✨✨

  • @tanishq2766
    @tanishq2766 Рік тому +1

    I solved this without any extra space, making the additions in the node itself, was a bit complicated but yet it worked !

  • @settyruthvik6236
    @settyruthvik6236 3 роки тому +9

    #code in python
    # Definition for singly-linked list.
    # class ListNode:
    # def __init__(self, val=0, next=None):
    # self.val = val
    # self.next = next
    class Solution:
    def addTwoNumbers(self, A: Optional[ListNode], B: Optional[ListNode]) -> Optional[ListNode]:
    l3=ListNode(0)
    head=l3
    carry=0
    while A or B or carry:
    if A:
    carry += A.val
    A=A.next
    if B:
    carry += B.val
    B=B.next
    l3.val=carry%10
    carry=carry//10
    if A or B or carry:
    l3.next=ListNode(0)
    l3=l3.next
    return head

  • @avadheshsingh4255
    @avadheshsingh4255 3 роки тому +3

    You are amazing best programming teacher on youtube keep it up brother

  • @hrishitsarkar6388
    @hrishitsarkar6388 2 роки тому +1

    Striver You are GREAT !!!!! Love from West Bengal

  • @NagaVijayKumar
    @NagaVijayKumar 4 роки тому +4

    Thank you bro..
    For uploading multiple videos in a single day..

  • @gamingwithhemend9890
    @gamingwithhemend9890 2 роки тому +2

    Love your simple and clean explanation 💯💯📸

  • @hemanthvarmas
    @hemanthvarmas 4 роки тому +2

    Nicely put explanation (as always) for "how to add two numbers given as Linked Lists". Thanks bro.

  • @reallydarkmatter
    @reallydarkmatter 3 роки тому +5

    You are really amazing at explaining every concept clearly

  • @prabaljain5887
    @prabaljain5887 3 роки тому +9

    i was solving this question on leetcode and the logic hit me in just 2mins but i wasn't able to code it

  • @ujjwalgupta518
    @ujjwalgupta518 2 роки тому +1

    Now I have the clearity on this question...thx ❤️

  • @Metalrave
    @Metalrave 2 роки тому +6

    I was able to do this in O(1) space as well with some optimisation (adding the sum values in the given listnodes only). Wouldn't that be a better answer to give to an interviewer?

    • @aakashgupta7211
      @aakashgupta7211 2 роки тому +2

      We should try not to make any changes to the input provided.

    • @GameZone-yd8kr
      @GameZone-yd8kr 2 роки тому

      That's My Nigg@ !
      I did that too !
      Kinda Noob Solution but u get the 💡 :
      class Solution {
      public:
      ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
      ListNode *ans = l1,*prev;
      int carry = 0;
      while(l1 && l2){
      int sum = l1->val+l2->val+carry;
      if(sum > 9){
      carry = 1;
      l1->val = sum-10;
      }
      else{
      carry = 0;
      l1->val = sum;
      }
      prev = l1;
      l1 = l1->next;
      l2 = l2->next;
      }
      if(carry){
      prev->next = l1 ? l1 : l2;
      while(l1){
      int sum = l1->val+carry;
      if(sum > 9){
      carry = 1;
      l1->val = sum-10;
      }
      else{
      carry = 0;
      l1->val = sum;
      }
      prev = l1;
      l1 = l1->next;
      }
      while(l2){
      int sum = l2->val+carry;
      if(sum > 9){
      carry = 1;
      l2->val = sum-10;
      }
      else{
      carry = 0;
      l2->val = sum;
      }
      prev = l2;
      l2 = l2->next;
      }
      if(carry){
      ListNode *node = new ListNode(carry);
      prev->next = node;
      }
      }
      else
      prev->next = l1 ? l1 : l2;
      return ans;
      }
      };

    • @tanishq2766
      @tanishq2766 Рік тому

      oh alright@@aakashgupta7211

  • @DeepakGupta-zz1vf
    @DeepakGupta-zz1vf 4 роки тому +9

    we can also do like while(l1!=null || l2!=null) and after loop we can check if carry>0 then make a node else dont make

    • @muktadirkhan6674
      @muktadirkhan6674 3 роки тому +2

      Yeah saw this approach on the LeetCode solution.

  • @vishalrane1439
    @vishalrane1439 9 місяців тому

    bhai ekdam simple karke bataya, Thanks bro

  • @techdemy4050
    @techdemy4050 4 роки тому +2

    It was a really awesome explanation if you don't mind can you make a video on " k Queues in a single array " and " k Stack in a single array " when you START WITH STACK and QUEUE because I am not able to understand these two questions.

  • @aravinds6406
    @aravinds6406 Рік тому +1

    Well Explained

  • @vakhariyajay2224
    @vakhariyajay2224 2 роки тому +2

    Thank you very much. You are a genius.

  • @jatinkumar4410
    @jatinkumar4410 2 роки тому +2

    Nice and clear explanation. One question... Should we consider the space used by output list when calculating space complexity?

  • @Karan-vq5vg
    @Karan-vq5vg 3 роки тому +1

    Amazing video...cleared all the doubts

  • @princepavan-ip1lg
    @princepavan-ip1lg Рік тому

    Awesome explaination sir ji👏👏👏👏

  • @ritikashishodia675
    @ritikashishodia675 3 роки тому

    Great bhaiya... U always inspiration..... I am stuck in that problem.... Thanks to give idea and approach I am appreciate and to u always

  • @dhruvrajput5194
    @dhruvrajput5194 4 роки тому +8

    Finally a question i figured out myself😂

  • @kaichang8186
    @kaichang8186 3 місяці тому

    understood, thanks for the detail explanation

  • @SudhanshuKumar-lp1nr
    @SudhanshuKumar-lp1nr 3 роки тому +2

    Why do we need the dummy node in the starting why can't directly start from first sum value?

  • @adarshurmaliya9901
    @adarshurmaliya9901 3 роки тому +1

    Great Explanation 👍

  • @manishmotwani3744
    @manishmotwani3744 4 роки тому +4

    That #striver sir for providing such a wonderful content. It helps me a lot!!

  • @deepgajjar5275
    @deepgajjar5275 2 роки тому +2

    we can optimize space complexity by first calculating the sum and then using old linked list nodes to create a sum linked list

    • @Raju_Sharma852
      @Raju_Sharma852 Рік тому

      Yeah, i did the same while solving this problem. But we should not temper the input files/lists untill and unless we are allowed to do so. Better ask the interviewer whether modification to the input files is allowed or not.

  • @-ShangsitNath
    @-ShangsitNath 2 роки тому +2

    Can we optimise the space by modifying anyone of the linked list and returning the head of that linked list ??

  • @ashdeepsingh6785
    @ashdeepsingh6785 2 роки тому +1

    can someone pls explain me why are we checking for carry == 0 and exiting if carry is 0. It is possible that we add two numbers like 2+3 it wont generate carry and yet the list can continue to have more numbers.

  • @ankitbhatt5630
    @ankitbhatt5630 2 роки тому

    Good Explanation!

  • @nabilafzal2984
    @nabilafzal2984 3 роки тому

    Awesome explanation ..thanks Bhaiya

  • @willturner3440
    @willturner3440 3 роки тому +1

    I think your approach better but not most optimized one
    Brother what if the interviewer say add without reversing

  • @amansingh.h716
    @amansingh.h716 Рік тому

    iS THIS CORRECT BRUTEFORCE WHAT I AM THINKING
    if we Store these 2 link list in string then reverse it then parse this in INTEGER and then sum it and then again store this in string and then reverse it , and at last iterate it create new nodes link them .

  • @sourabhchoudhary7289
    @sourabhchoudhary7289 3 роки тому

    if list are not given in rev oreder then brute can be to make int out of linked list then Add them both and make new linked list of ans integer.

  • @RM-lb7xw
    @RM-lb7xw 4 роки тому

    Great video bro, keep it up 👌

  • @priyankarai7005
    @priyankarai7005 4 роки тому +5

    instead of creating a new list we can just put the sum of every corresponding nodes in the nodes of the lists itself. Space complexity becomes from O(n) to O(1)

    • @takeUforward
      @takeUforward  4 роки тому +24

      No you cannot as it us said dont destroy the given lists.

    • @laxminarayanchoudhary939
      @laxminarayanchoudhary939 3 роки тому +3

      @@takeUforward Thank you clearing, Same O(1) space complexity came in my mind.

    • @shri9229
      @shri9229 2 роки тому +1

      intresting point anyways

  • @pranayghosh7912
    @pranayghosh7912 3 роки тому

    bhaia what is the difference betweeen striver n take u forward did u stopped striver?

  • @abhirajtyagi9244
    @abhirajtyagi9244 4 роки тому +1

    Nice sir je👌👌

  • @28_vijayadityarajr12
    @28_vijayadityarajr12 Рік тому +1

    lovely vedio

  • @bhagyashri7729
    @bhagyashri7729 2 роки тому

    can we do it in single temp node and avoid having 2 dummy pointers?

  • @itsugo_
    @itsugo_ 3 роки тому

    Thank you!

  • @aditik2233
    @aditik2233 4 роки тому

    understood Thank you

  • @praharshsingh2095
    @praharshsingh2095 4 роки тому +2

    What is the significance of using dummy pointer ?

    • @ajvindersingh6835
      @ajvindersingh6835 3 роки тому

      JUST TO STORE THE ADDRESS OF FIRST NODE😉

    • @achinttrivedi4667
      @achinttrivedi4667 2 роки тому

      ​@@ajvindersingh6835 ​ @take U forward but where we are storing the address of first node can you explain please?
      and why we are returning dummy's next ?

  • @AKD4536
    @AKD4536 3 роки тому

    Amazing explanation

  • @aryansinha1818
    @aryansinha1818 2 роки тому +1

    8:22 C++ Code

  • @exdee8446
    @exdee8446 2 роки тому

    Why are we checking if (carry == 1) for loop's termination?

    • @p0tat0627
      @p0tat0627 2 роки тому

      cause consider an example two list l1, l2 having only single digits, 8 & 7. If u sum it up u get 15. U add 5 to the new_list, the carry 1 gets ignored if u consider only l1 and l2 cause in the next loop l1 & l2 both null, but u still have 1 as carry left. Thats why carry should also be considered for the loop going..

  • @surajsah3361
    @surajsah3361 2 роки тому

    I have a doubt, when we are returning dummy.next why it is returning whole node and why not the single node of dummy.next.

    • @tejaspatel2212
      @tejaspatel2212 2 роки тому

      It's the inbuilt implementation of leetcode for evaluation. Here, in leetcode when you return dummy.next, it will return the whole node same goes for return head.
      Hope this helps :)

  • @freshcontent3729
    @freshcontent3729 3 роки тому

    bro but this can be done without extra space also right ? that is withought making a whole new linked list ( the sum one )

  • @PranathNaik
    @PranathNaik 3 роки тому

    nice explaination

  • @VivekGuptaMusic
    @VivekGuptaMusic 3 роки тому +1

    in c++ why you are returning the next of the dummy node we could direct start from the starting of the linked list

  • @ankitnegi4802
    @ankitnegi4802 2 роки тому

    instead of || there should be && in while loop condition ...please clear it am i right or not??

    • @neerajmahapatra5239
      @neerajmahapatra5239 2 роки тому +1

      Actually && will be be for stopping the while loop. But in while loop we are writing condition that should move the while loop... If any one of them is satisfied means if either n1 is not null or n2 is not null or carry is not 0 we have to move... It's not like if all of them satisfy then we have to move... Just say it in English you will get to know either we have to use && or ||

  • @amanjot3492
    @amanjot3492 2 роки тому

    Good solution

  • @krishnavamsichinnapareddy
    @krishnavamsichinnapareddy Рік тому

    Understood 🔥

  • @aakashdabas9490
    @aakashdabas9490 4 роки тому +1

    why u did ' || ' not ' && ' : why this, while(l1 != NULL || l2 != NULL || carry!=0 ) not while(l1 != NULL && l2 != NULL && carry!=0 )
    We have to check untill each of the l1 becomes NULL.
    Please answer sir!

    • @coding6409
      @coding6409 4 роки тому +2

      if you use an && then this code will not work if the linked lists are not equal, using an || takes consideration of that edge case

  • @gautamsuthar4143
    @gautamsuthar4143 3 роки тому

    It took me time but I wrote the code exactly same as you did.

    • @freshcontent3729
      @freshcontent3729 3 роки тому

      bro but this can be done without extra space also right ? that is withought making a whole new linked list ( the sum one )

    • @wog4299
      @wog4299 Рік тому

      @@freshcontent3729 on which lists will you stored l1 or l2 , and how will you find which is greater and if the sum exceeds the list then again you will have to add a new Node which I guess taking a new list is great instead of modifying the given list

  • @GurpreetSingh-ps6kl
    @GurpreetSingh-ps6kl 3 роки тому

    thank you

  • @shouvikdatta6831
    @shouvikdatta6831 4 роки тому

    Thnx vai❤

  • @tekken1935
    @tekken1935 3 роки тому +3

    Striver Bhaiya, do you think that having such SDE sheets, interviewer might explicitly look at the questions in such SDE sheets and not repeat these particular questions?

    • @amansinghal4663
      @amansinghal4663 Рік тому

      exactly what i am thinking.... interviewers also know that nowadays everyone is doing these sde sheets so they will definitely not ask questions present in it

  • @riaria5982
    @riaria5982 Рік тому

    sum += carry;
    carry=sum/10;
    Isn't it butcher the sum value?
    It should be:
    carry= sum/10
    sum = sum+ carry;

  • @cossMania
    @cossMania Рік тому

    Thanks man

  • @mohdkhaleeq7468
    @mohdkhaleeq7468 2 роки тому

    on take you forward website space complexity is written O(max(m,n)) and you said O(n) it is confusing

    • @aryansingh7101
      @aryansingh7101 2 роки тому

      O(max(m,n)) will return the maximun of size od n or m, so it can be O(n) or O(m)

  • @om_1_2
    @om_1_2 4 роки тому

    Got it bro👍👍

  • @avishekroy1642
    @avishekroy1642 3 роки тому

    great content

  • @pragyavyas186
    @pragyavyas186 4 роки тому

    We can do it without using the extra space also.

    • @takeUforward
      @takeUforward  4 роки тому +2

      That will be destroying the original list, which is not allowed, also since you returning the answer which is taking space, it is okay!

  • @prashantraj6366
    @prashantraj6366 2 роки тому

    Can 1 of 2 linked list be used instead of dummy node? If not, then why not?

    • @EntEduRealm
      @EntEduRealm 2 роки тому

      ua-cam.com/video/gpg6-DOdlxw/v-deo.html watch this if you dont understand

    • @neerajmahapatra5239
      @neerajmahapatra5239 2 роки тому

      Unable to understand what are you asking for

    • @p0tat0627
      @p0tat0627 2 роки тому

      U can't change the input list, also it is not recommended to modify the input data structure

  • @syedyaseenabbasrizvi8072
    @syedyaseenabbasrizvi8072 4 роки тому

    Can you please tell the intuition behind this approach..?

    • @takeUforward
      @takeUforward  4 роки тому +7

      Its a simple algo, why do you need intuition. Isn’t it straightforward to add them like that, simple maths stuff!

    • @syedyaseenabbasrizvi8072
      @syedyaseenabbasrizvi8072 4 роки тому

      @@takeUforward Alright got it..thanku

  • @rohankrishnani
    @rohankrishnani 2 роки тому

    please solve it without using space one time, i tried and am stuck with one testcase

  • @jaysaxena185
    @jaysaxena185 4 роки тому

    Bro, your c++ solution is very nice but lc giving time limit exceeded while submission of c++ code, please help in optimizing this. Thanks

    • @takeUforward
      @takeUforward  4 роки тому +4

      The code explained was an accepted solution, cross check for typos or some extra lines that you would have added..

    • @sparks8754
      @sparks8754 3 роки тому +3

      yes, it is showing TLE on leetcode

  • @elements8630
    @elements8630 3 роки тому

    nice video.

  • @karangoyal7386
    @karangoyal7386 4 роки тому +1

    Bhaiya I was dropper but not selected should I go for local college in my city

  • @curiousMe1000
    @curiousMe1000 2 роки тому

    Why we need the dummy nood in the beginning?

  • @sakshamsrivastava6280
    @sakshamsrivastava6280 3 роки тому +1

    hands down !!

  • @nitingupta1417
    @nitingupta1417 3 роки тому +1

    can't it be done in O(1) space complexity

    • @takeUforward
      @takeUforward  3 роки тому

      then you have to reuse the given linkedlist only, which is not advisable..

    • @nitingupta1417
      @nitingupta1417 3 роки тому

      @@takeUforward understoood... and thanks for your reply 😁

    • @devinenisowmya1479
      @devinenisowmya1479 3 роки тому

      @@takeUforward can u explain why it is not advisible

    • @nitingupta1417
      @nitingupta1417 3 роки тому

      @@devinenisowmya1479 becasue the input linked list will get distorted... sometimes we are not allowed to modify the inputs...

  • @yashas3567
    @yashas3567 3 роки тому +1

    can u make a video for the same question if head points to the most significant digit

    • @sudheerg9182
      @sudheerg9182 3 роки тому +1

      then you need to reverse both list and do the same as explained

  • @shashankgsharma0901
    @shashankgsharma0901 6 місяців тому

    Understood!

  • @kishanyadav-ob4xl
    @kishanyadav-ob4xl 2 роки тому

    Thanks sir

  • @amanchandok685
    @amanchandok685 4 роки тому

    When do you plan to finish this series?

  • @geekieyyy
    @geekieyyy 3 роки тому

    Sir can u give the link of the doc file which u showed in starting of this video PLs

  • @aakashSky-0
    @aakashSky-0 Рік тому

    There would be a memory leak in this for dummy. So make sure you delete it at the end before returning.

  • @karthikrashinkar204
    @karthikrashinkar204 3 роки тому +2

    Why this condition is used in while loop
    Carry ==1
    Can anyone explain please

  • @yashchandan7313
    @yashchandan7313 4 роки тому

    Thankyouu!

  • @abhishekbajpai5188
    @abhishekbajpai5188 4 роки тому +2

    Bhaiya ye btaiye ki c++ ds algo kahan se crein

  • @preetitripathi6280
    @preetitripathi6280 2 роки тому

    This solution is giving wrong answer for some test cases.What should be other edge cases which should be taken into consideration?

    • @GameZone-yd8kr
      @GameZone-yd8kr 2 роки тому

      Check my Constant Space Solution (C++) : 😘😘
      class Solution {
      public:
      ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
      ListNode *ans = l1,*prev;
      int carry = 0;
      while(l1 && l2){
      int sum = l1->val+l2->val+carry;
      if(sum > 9){
      carry = 1;
      l1->val = sum-10;
      }
      else{
      carry = 0;
      l1->val = sum;
      }
      prev = l1;
      l1 = l1->next;
      l2 = l2->next;
      }
      if(carry){
      prev->next = l1 ? l1 : l2;
      while(l1){
      int sum = l1->val+carry;
      if(sum > 9){
      carry = 1;
      l1->val = sum-10;
      }
      else{
      carry = 0;
      l1->val = sum;
      }
      prev = l1;
      l1 = l1->next;
      }
      while(l2){
      int sum = l2->val+carry;
      if(sum > 9){
      carry = 1;
      l2->val = sum-10;
      }
      else{
      carry = 0;
      l2->val = sum;
      }
      prev = l2;
      l2 = l2->next;
      }
      if(carry){
      ListNode *node = new ListNode(carry);
      prev->next = node;
      }
      }
      else
      prev->next = l1 ? l1 : l2;
      return ans;
      }
      };
      It Passes All test Cases and is pretty Efficient 😍

  • @ghoshdipan
    @ghoshdipan 4 роки тому

    Why is it that I'm not able to solve it optimally!

  • @hy-ti1ic
    @hy-ti1ic 2 роки тому

    Wow 😍

  • @Nikhil-qd9up
    @Nikhil-qd9up 3 роки тому +1

    OPTIMAL - We can also do it inplace without taking a dummy linkedlist

    • @freshcontent3729
      @freshcontent3729 3 роки тому

      but then why did striver say that this is the only optimal solution do this problem ? is he wrong ? please help me i am confused

    • @Nikhil-qd9up
      @Nikhil-qd9up 3 роки тому

      @@freshcontent3729 no bro he is correct,what i said was doing it inplace

    • @freshcontent3729
      @freshcontent3729 3 роки тому

      @@Nikhil-qd9up but bro doing inplace is optimal right ? as it is way better . cause we aint using space.

    • @Nikhil-qd9up
      @Nikhil-qd9up 3 роки тому

      @@freshcontent3729 yes bro

    • @freshcontent3729
      @freshcontent3729 3 роки тому

      @@Nikhil-qd9up so in interview which one should i tell ?

  • @willturner3440
    @willturner3440 3 роки тому

    Bhaiya what if the interviewer says add two list without reversing it?

  • @saisagarsharma
    @saisagarsharma 3 роки тому +1

    Hiee. is Space complexity o(n)? isnt max(m,n)? please clarify

    • @EntEduRealm
      @EntEduRealm 2 роки тому

      ua-cam.com/video/gpg6-DOdlxw/v-deo.html watch this if you dont understand

  • @subhajeetchakraborty1791
    @subhajeetchakraborty1791 2 роки тому

    understoooood

  • @SatyamKumar-dj3jo
    @SatyamKumar-dj3jo 3 роки тому

    why carry is always 1? carry can be zero, right?

  • @pratikshadhole6694
    @pratikshadhole6694 2 роки тому

    awesome bhai

  • @nandankakadiya1494
    @nandankakadiya1494 3 роки тому +1

    I have a question how dummy's next is pointing to head?

    • @EntEduRealm
      @EntEduRealm 2 роки тому

      ua-cam.com/video/gpg6-DOdlxw/v-deo.html watch this if you dont understand

  • @snegar1677
    @snegar1677 2 роки тому

    how dummy -> next is giving the answer, can anyone tell me pls

  • @hemanthv4918
    @hemanthv4918 3 роки тому

    How about using one of the two linked lists( greater length) to store the answer. In that way we even save space.

    • @bharathkumar5870
      @bharathkumar5870 3 роки тому

      yes i have did like that..it worked

    • @factfactorial632
      @factfactorial632 2 роки тому

      bro it will increase time complexity on the other hand becuse we will have to figure it out which one is greater

    • @prakhargupta1745
      @prakhargupta1745 Рік тому

      @@factfactorial632 rather just store it in one of the two linked lists regardless of the size and once that reaches NULL, let the last pointer point to the first element of the 2nd linked list and then store it in that list. This way u will not have to traverse the length of the linked list to check which one is longer

  • @saketkumar7335
    @saketkumar7335 4 роки тому

    kindly compile and run this code also

    • @takeUforward
      @takeUforward  4 роки тому +1

      Its an accepted code that I explain :)