Add two numbers represented by linked lists

  Рет қаралды 65,636

Vivekanand Khyade - Algorithm Every Day

Vivekanand Khyade - Algorithm Every Day

Күн бұрын

Пікірлер: 80
@Official-tk3nc
@Official-tk3nc 4 жыл бұрын
if you are watching this in lockdown believe me you are one of the rare species on the earth who is working hard to achieve something in life. Many students are wasting their time watching movies, playing pubg, watching netflix , etc, ALL THE BEST nitjstudenthere
@pruthvirajk6019
@pruthvirajk6019 4 жыл бұрын
which yr
@Official-tk3nc
@Official-tk3nc 4 жыл бұрын
@@pruthvirajk6019 1st yr
@Official-tk3nc
@Official-tk3nc 4 жыл бұрын
@@pruthvirajk6019 and u?
@pruthvirajk6019
@pruthvirajk6019 4 жыл бұрын
@@Official-tk3nc PUC 1
@heya2k198
@heya2k198 4 жыл бұрын
@@Official-tk3nc 1st yr me itna kyu padh rha bhai...relax ho jaa....
@agraa
@agraa 4 жыл бұрын
While adding when you are creating new linked list, just add the new node in the begining not in the end, so in that case you dont need to reverse it again. btw this question was asked to me in amazon interview.
@piyushbabbar2919
@piyushbabbar2919 4 жыл бұрын
Didn't ask
@Official-tk3nc
@Official-tk3nc 4 жыл бұрын
Yeah good optimization. Even i thought the same
@piyushkumar-et2vb
@piyushkumar-et2vb 4 жыл бұрын
nice bro
@spardha-yug
@spardha-yug 2 жыл бұрын
khup chhan bhava. Ekdam sopya bhashet ani chhan explain kelas.
@ashermanangan
@ashermanangan 4 жыл бұрын
What a great explanation. Thanks for this one, I now have a glimpse on what I should do on this Machine Problem
@sanjayjoshi8807
@sanjayjoshi8807 4 жыл бұрын
optimizations could be done like no need to calculate length and difference to add zeroes we can reduce that step
@anirudhsharma8608
@anirudhsharma8608 4 жыл бұрын
You are probably the best teacher on planet earth! Thank you so much for this !!!!!!
@brinderdhaliwal3570
@brinderdhaliwal3570 7 жыл бұрын
my friend, very good examples. You are really helping me for my interview preparation that is coming up.
@faz_1337
@faz_1337 4 жыл бұрын
Great video, you explained it slowly and clearly.
@prnk139
@prnk139 2 жыл бұрын
Good ! Great Way of explaination!
@Techjai000
@Techjai000 3 жыл бұрын
you are amazing sir nice video
@100_bindusai8
@100_bindusai8 4 жыл бұрын
Great explanation sir🙂😊😊
@19osnaldito
@19osnaldito 7 жыл бұрын
You just saved my life. Thanks. Excellent video!!!! #handsdown
@letsexplorewith_jaggu98
@letsexplorewith_jaggu98 4 жыл бұрын
Thank you so much sir : ) you are really helping us in a great way
@aryambham1006
@aryambham1006 5 жыл бұрын
Can't thank you enough for the detailed explanations
@saicharan8675
@saicharan8675 5 жыл бұрын
Sir beautifully done... Thank for the lecture
@narayananrenganathan765
@narayananrenganathan765 5 жыл бұрын
@Vivekanand Khyade your videos are very helpful for us. Thanks a lot !!
@RohitPal-sc3um
@RohitPal-sc3um 4 жыл бұрын
Nice sir You are doing well
@samrat4141
@samrat4141 11 ай бұрын
Super explanation
@smayengbam
@smayengbam 5 жыл бұрын
Thanks Vivek for another awesome video!
@anujjain1456
@anujjain1456 4 жыл бұрын
sir plz also analyse time complexity of solution that's makes ur lectures unbeatable thanks sir for superb content
@mathewwade4679
@mathewwade4679 4 жыл бұрын
Another approach: This will take a bit more space(2 extra strings) compared to what sir discussed but it will also save a lot of computations. But note that space complexity still remains O(N) in both approaches. So first create 2 empty strings - str1 & str2 Traverse the first linked list. At each node append it to our string. Convert this string to an integer - firstNum Similarly traverse second linked list and get - secondNum Add both of them: result = firstNum + secondNum Convert result to a string now For each character in result string: add it to a new node at insert at the end of our new Linked List. Return the new Linked List.
@sauravbhagat4737
@sauravbhagat4737 6 жыл бұрын
sir, we can do same without finding length and inserting zero ? As we are reversing already, we will just put check if(p->next!=NULL) //then do this. btw very smothly explained.
@SagarSharma-ej3ds
@SagarSharma-ej3ds 4 жыл бұрын
How to subtract two linked list Sir ? If possible please give the git code.
@ShreyaSingh-vr9qi
@ShreyaSingh-vr9qi 4 жыл бұрын
Can we modify one of original linked list to store the current both list nodes sum in one of existing linked list. It will reduce space complexity ??
@yatinarora1252
@yatinarora1252 3 жыл бұрын
I thought so as I will add the sum in linked list. and then done its reversed trversal...Actually I was able to do that but some sort of overflow was there in my algo
@sharjeeltahir5583
@sharjeeltahir5583 4 жыл бұрын
Remainder of 8/10 is not zero, but 8. 10 goes into 8 zero times, hence the remainder is 8.
@raushanraj227
@raushanraj227 2 жыл бұрын
well explained
@anilnkhsatriya9047
@anilnkhsatriya9047 6 жыл бұрын
i think its more efficient by using double linked list. anyway good explanation tqu.
@brinderdhaliwal3570
@brinderdhaliwal3570 7 жыл бұрын
also, this means that at the end..you are returning a linked list..correct?
@adityagupta-lw1nt
@adityagupta-lw1nt 4 жыл бұрын
how to solve this question without reversing the linked list
@vincentmanlesis8698
@vincentmanlesis8698 5 жыл бұрын
What if you input two digit number. It is needed to separate it right? Example : 10 11 12 13
@salonirathi1158
@salonirathi1158 7 жыл бұрын
Thank you Sir:)
@sayantaniguha8519
@sayantaniguha8519 3 жыл бұрын
Plz make video for *Large number Arithmetic* using DLL.
@Ashish.Shukla9
@Ashish.Shukla9 5 жыл бұрын
can't we do it without reversing???
@ChipsAhoy2022
@ChipsAhoy2022 6 жыл бұрын
This is required to be done without reversing the lists. Otherwise the solution is trivial and is definitely not what the interviewer expects. Can you please explain how to do the same.
@s.l5787
@s.l5787 6 жыл бұрын
This is a technical detail but the remainder between 8 divided by 10 is actually 8, not 0. So in the cases where the carry is 0, it just means the addition variable and the remainder variable will be equal. e.g 8%10 yields 8 .
@ASHISHSHARMA-eg6oi
@ASHISHSHARMA-eg6oi 7 жыл бұрын
nice sir...Come up with more problems like from codechef and hacker-rank .Thanks in advance:)
@harshalgarg1149
@harshalgarg1149 4 жыл бұрын
Sir, your github link is not working. Please help.
@kranthiraj667
@kranthiraj667 4 жыл бұрын
In either case reminder can go into new node. 5%10 = 5 not 0
@shibanidas1479
@shibanidas1479 7 жыл бұрын
sir, if i want to multiply two numbers from diff linked lists and store the output no in a different. how can i do it?? can u just show it?? thank you .
@trishulsherigar1961
@trishulsherigar1961 4 жыл бұрын
This problem has a recursive solution right?
@swacharahman5084
@swacharahman5084 4 жыл бұрын
Why Don't you provide the code link in the description..😐 please do it
@ghoshdipan
@ghoshdipan 4 жыл бұрын
Sir please show the full workinh of code also then it would be of much help.
@ashiqhussainkumar1391
@ashiqhussainkumar1391 3 жыл бұрын
I've a simple approach : Adding K lists in general. 1.Reverse list 1, list 2,....list k;//as many lists u want to add. 2. Initialize sum1=0,.... sumk=0; 3.initialize a = 1;//used in addition. 4. temp1 = head1; while (temp1) { sum1 += temp1.data *a; a=a*10; temp1 = temp1.next ; } 5.Reinitialize a = 1; Repeat process for other K-1 lists. 6.return sum1 + sum2+... sumk;
@VivekKumar-zo7kr
@VivekKumar-zo7kr 4 жыл бұрын
Can please anyone help me... I have one another method... Instead of naming a variable carry... We can increase the p->next data by 1... And for corner cases if p->next ==NULL then just add the last digits.. Can we do so na?
@myaseen7419
@myaseen7419 4 жыл бұрын
great explanation sir. i want code please.
@gv6980
@gv6980 7 жыл бұрын
Your videos are awesome. Can I get code in C++?
@chitraanandh6499
@chitraanandh6499 6 жыл бұрын
sir, can you please make an explanatory video for polynomial addition using linked list?
@DhruvilPatel
@DhruvilPatel 4 жыл бұрын
Your program took more time than expected. This is coming in GFG please HELP
@mohamedmusaraf675
@mohamedmusaraf675 4 жыл бұрын
don't make zero values as a node Node* addTwoLists(Node* first1, Node* second1) { Node* res = NULL; Node *temp, *prev = NULL; int carry = 0, sum; while (first1 != NULL || second1 != NULL) { sum = carry + (first1? first1->data: 0) + (second1? second1->data: 0); //if the data is null then make the value as zero bro!!!1 carry = (sum >= 10)? 1 : 0; sum = sum % 10; temp = newNode(sum); if(res == NULL) res = temp; else prev->next = temp; prev = temp; if (first1) first1 = first1->next; if (second1) second1 = second1->next; } if (carry > 0) temp->next = newNode(carry); return res; } i too solved today bro!
@smritikaushik7529
@smritikaushik7529 4 жыл бұрын
Pls provide the complete code
@lelehehe
@lelehehe 4 жыл бұрын
it is mod, not divide by 10.
@soumyamothe2981
@soumyamothe2981 6 жыл бұрын
Sir I need infix and postfix program by using stack
@quadirnawaz67
@quadirnawaz67 6 жыл бұрын
Search it on "My code school data structure playlist" You'' find them.
@bhuvanchandmaddi800
@bhuvanchandmaddi800 6 жыл бұрын
github.com/vivekanand44/codes-KZbin-videos/blob/master/add_two_numbers_linked_list.cpp sir in your above code on git hub,there is some change(second if condition n1-n2) i think so because it gives wrong output when size of second list is greater than first and according to your code there is no need of appending zero infront of list after reversing..concept was super thank you sir..i have been following your lectures and your are the best
@nands4410
@nands4410 6 жыл бұрын
if (n1 > n2) { diff = n2 - n1; flag = 1; } He made a mistake here. diff = n1-n2; is correct
@libalalolaq9951
@libalalolaq9951 7 жыл бұрын
how to solver this question whihout reversing?
@yashpreetbathla4653
@yashpreetbathla4653 5 жыл бұрын
use recursion ,it will be lil more complex
@deepak1725
@deepak1725 6 жыл бұрын
Whenever i hear .. Hello Frands, I complete it by.. "Chai pee lo".
@neghatnazir1668
@neghatnazir1668 4 жыл бұрын
Lol!
@RohitPal-sc3um
@RohitPal-sc3um 4 жыл бұрын
When i see Bakchod like you , I Complete it by .."Muh me Lelo....."
@vikashsharma5844
@vikashsharma5844 2 жыл бұрын
Code wode yahi dala karo yrr...Ab github par jaao ID banao ...dhundo kaha hai kaun saa hai ...
@farhanjamal1376
@farhanjamal1376 5 жыл бұрын
do it on the computer.........what is this
@IamShivaniPandit
@IamShivaniPandit 7 жыл бұрын
Too slow. Speak fast and make short videos.
@deepikatadakhe
@deepikatadakhe 7 жыл бұрын
you can increase the speed of the video to your convenience
@GauravSharma-wb9se
@GauravSharma-wb9se 7 жыл бұрын
Everyone is not fast like you so its good for them
@bipros7
@bipros7 6 жыл бұрын
yeah man!!! I've increased the speed to 1.5x...still the speed seems like normal
Remove duplicate elements(nodes) from an Unsorted list
13:00
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 62 М.
Swap nodes in a linked list without swapping data (Very Easy Explanantion)
20:54
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 56 М.
When Cucumbers Meet PVC Pipe The Results Are Wild! 🤭
00:44
Crafty Buddy
Рет қаралды 60 МЛН
СКОЛЬКО ПАЛЬЦЕВ ТУТ?
00:16
Masomka
Рет қаралды 3,5 МЛН
Long Nails 💅🏻 #shorts
00:50
Mr DegrEE
Рет қаралды 17 МЛН
L5. Add 2 numbers in LinkedList | Dummy Node Approach
14:48
take U forward
Рет қаралды 116 М.
Understanding and implementing a Linked List in C and Java
18:15
Jacob Sorber
Рет қаралды 245 М.
How to STUDY so FAST it feels like CHEATING
8:03
The Angry Explainer
Рет қаралды 1,9 МЛН
Swap nodes pairwise in Linked List (nodes in pairs)
15:14
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 44 М.
Application of Linked List (Addition of Two Polynomials)
17:29
Neso Academy
Рет қаралды 215 М.
Towers of Hanoi: A Complete Recursive Visualization
21:13
Reducible
Рет қаралды 493 М.
Reverse a Linked List Code/Algorithm/Program
9:03
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 108 М.