L2. Deletion and Insertion in LL | 8 Problems

  Рет қаралды 248,361

take U forward

take U forward

Күн бұрын

Пікірлер: 243
@samxd4296
@samxd4296 Жыл бұрын
0:00 Intro 0:34 Deletion of the head of LL 6:18 Deletion of the tail of LL 15:47 Deletion of the Kth element of LL 30:14 Delete the element with value X 32:15 Insertion at the head of LL 35:15 Insertion at the tail of LL 38:41 Insertion at the Kth position 51:22 Insertion before the value X Thank You Striver for the Playlist and your hard work
@GotetiKrishnasrikar
@GotetiKrishnasrikar 3 ай бұрын
@immortal6978
@immortal6978 Жыл бұрын
A hell lot of hardweork for the community. Hat's off your dedication to coding. Hit like on video if Agreed.
@AnshGupta-pr7qo
@AnshGupta-pr7qo Ай бұрын
How could someone be so perfect at explaining.....literally hats off to you striver If in life i ever had a chance to meet or see you it'll be one of mt best day
@loremvampire6343
@loremvampire6343 Жыл бұрын
I was waiting for this playlist since one month. Thank you so much Sir
@chrish4403
@chrish4403 2 ай бұрын
So grateful , Linked list is a topic ive been avoiding to learn from my boards due to lack of understanding, but in just two videos you have made me so well versed with linked list, wish i found this video two years ago,
@vedikamishra009
@vedikamishra009 Күн бұрын
same, but 2 years ago it didn't exist sadly :(
@publicuses8589
@publicuses8589 Жыл бұрын
Striver bhaiya u r a gemmmmm lot's of respect for u 🫡🫡
@ronakvaghela2714
@ronakvaghela2714 3 ай бұрын
One of the best coding content on the whole youtube. You're an inspiration to everyone and a great example of how hardwork looks like. Thanyou so much for doing this. you deserve everything you wish for and hope to see such content more from you.
@5640_GlenaSAHA
@5640_GlenaSAHA 4 ай бұрын
you are the best one to teach linked list in the easiest manner, I wasted my whole third semester understanding linked list but still failed. But you are really amazing!!!!
@ShubhraneelChakraborty-cj8zm
@ShubhraneelChakraborty-cj8zm 4 ай бұрын
For insertion of a node at the head of the linked list, we can also do this: Node temp=head; head=val; head.next=temp; return head; What its doing is that, the previous head is being assigned to a temporary pointer, and the new node being inserted (val) is being assigned to the initial head pointer (head), a simple swap. Then the head's next is being assigned the temporary pointer (holding the initial head) to link the new head and the previous one. Hope that helps. And thank you Raj bhaiya for such an amazing video again, the explanation was so clear.
@GirishaMalani-fs4ch
@GirishaMalani-fs4ch 4 ай бұрын
but then what will be temp->next?
@ShubhraneelChakraborty-cj8zm
@ShubhraneelChakraborty-cj8zm 3 ай бұрын
@@GirishaMalani-fs4ch Forgot to mention, it is in Java, so it will be collected by the garbage collector. For C++, you need to free that pointer.
@VishalGupta-xw2rp
@VishalGupta-xw2rp Жыл бұрын
Notes 33:33 Insert at head 50:01 Delete Nicely done
@Ranganadhamkrishnachaitanya27
@Ranganadhamkrishnachaitanya27 8 ай бұрын
How code will work I'm confused
@anuragprasad6116
@anuragprasad6116 9 ай бұрын
For deletion at k index, you can check if(cnt == k-1) and perform curr->next = curr->next->next; instead of keeping a previous pointer.
@purvamjain4953
@purvamjain4953 3 ай бұрын
it wil give u error, assume u have 4 elements and they asked to remove 5th element. with cnt=k-1 it will try to access next element of null which will throw error unless u catch it manually
@sanjayutchula7849
@sanjayutchula7849 2 ай бұрын
In order to avoid this we can maintain a int size variable in class and declare it public update every time we add or delete node and for deleting a kth node we can check at starting if it exceeds the boundaries and throw an error else we can run a for loop for k times and move the temp pointer to reach before which we want to delete ​@@purvamjain4953
@VivekKumar-kx2zf
@VivekKumar-kx2zf 2 ай бұрын
@@purvamjain4953 no that can also be skipped using a if condition.. Look at this code : static Node DeleteAny(Node head, int k) { Node temp = head; if(k == 1) { head = head.next; return head; } for(int i = 1; temp != null;i++) { if(i == k-1 && temp.next!=null) { temp.next = temp.next.next; } temp = temp.next; } return head; }
@mdfaizanmdfaizan6041
@mdfaizanmdfaizan6041 Ай бұрын
​@@purvamjain4953we can apply for a condition before
@santhoshl-zq1op
@santhoshl-zq1op 22 күн бұрын
But , at the starting itself , we check the condition if( k > lengthof LL ) return head;
@AmanSharma-xy1qm
@AmanSharma-xy1qm 11 ай бұрын
All the video lectures and the articles helped me a lot to gain confidence in DSA and will be helping me in the interviews. Thank you Striver bhaiya for bringing such amazing content for free.
@hareshnayak7302
@hareshnayak7302 7 ай бұрын
Understood,Thanks striver for this amazing video.
@prathameshjadhav2942
@prathameshjadhav2942 Жыл бұрын
Next level teaching ❤
@utkarshsingh09
@utkarshsingh09 2 ай бұрын
His teaching skills!!! Hats off!
@5640_GlenaSAHA
@5640_GlenaSAHA 4 ай бұрын
believe me on this when i say he is the best!!
@vaishnavi.pvaishnavi.p8474
@vaishnavi.pvaishnavi.p8474 9 ай бұрын
superb explanation sir...... i want to listen you more and more
@dipingrover1970
@dipingrover1970 3 ай бұрын
Such a hard topic explained in best way possible Thanks a lot man 😊.
@S3aw0lf
@S3aw0lf 9 ай бұрын
Superb explanation, was able to do the code by myself starting from 2nd video after understanding you explanations.
@prajjwalsinghrathore9458
@prajjwalsinghrathore9458 Жыл бұрын
Thanks bhayya for the playlist, we appreciate it , it would be good if you add time-stamp to it.
@Rohit-ht8kd
@Rohit-ht8kd Ай бұрын
at 29th min the code for if(k == 1) is head = head.next; return head: but you have written Node temp = head: return head;
@prathamrajsrivastava9807
@prathamrajsrivastava9807 11 ай бұрын
hey striver... when's the strings playlist coming out??
@uchihaitachi5376
@uchihaitachi5376 5 күн бұрын
Striver love you bro how can you make things very simple thank s bro❤
@pranaycc
@pranaycc Жыл бұрын
Crisp And Detailed, 💕💕
@chetna253
@chetna253 2 ай бұрын
a lot of hardwork ...respect bruh
@GauravGupta-no7sf
@GauravGupta-no7sf 9 ай бұрын
00:04 Deletion and insertion in linked lists 02:21 Freeing memory in C++ and Java 06:58 To delete the last element in a linked list, the list must have at least two elements. 09:34 Deleting the tail element from a linked list 14:28 Demonstration of removing elements from a linked list in Java. 16:46 Deleting elements from a linked list 21:04 Discussing traversal and conditions for stopping 23:27 Managing deletion and insertion in a linked list 28:03 Removing elements from a linked list in Java 30:23 Deleting elements from a linked list based on given value. 34:35 Inserting before and after the head in linked list 36:44 Inserting a new node at the end of the linked list 41:06 Insertion in linked list at different positions 43:21 Traversing and manipulating temporary in linked list 48:12 Covering all the H cases for node insertion in a linked list 50:27 Inserting and deletion in linked list 54:42 Insertion before a value in a linked list
@glife54
@glife54 9 ай бұрын
Ai
@lordgaming7178
@lordgaming7178 20 күн бұрын
Thank you for the explanation
@AtanuDebnath
@AtanuDebnath 4 ай бұрын
Raj Dada , Love you! ❤❤❤ You make the hard things look so easy!
@sauravkumar9900
@sauravkumar9900 11 ай бұрын
Bhaiya please make a playlist videos on Strings from basic to advance
@Ady-tf1jm
@Ady-tf1jm 3 ай бұрын
Best Playlist for beginners.
@harshitgarg2820
@harshitgarg2820 Жыл бұрын
Completed this video and done all the 11 questions of the sheet.✅✅
@himanshukaushik9223
@himanshukaushik9223 10 ай бұрын
Bro last 2 questions ma compilation error bta Raha insertion ma sheet ka
@harshitgarg2820
@harshitgarg2820 10 ай бұрын
@@himanshukaushik9223 bhai typos me error hogi, ek baar dobara check kro fir run krna, agr vs code use krr rhe ho toh mingw ko reinstall krke dekho
@himanshukaushik9223
@himanshukaushik9223 10 ай бұрын
Bhai coding ninja pa last 2 question compile error bta rahe hai
@newbie8051
@newbie8051 4 ай бұрын
0:34 ha, my initial thought was to use a slow and fast pointer, and when fast pointer approaches the node to be deleted, we skip it by having next of slow pointer be the next node
@ompawar9791
@ompawar9791 Жыл бұрын
I searched for this kind of videoes from last few days. Now i got that man ->striver.........YOU CREATED ME AS A POINTER WHERE I STORED ADDRESS OF YOUR CHANNEL IN MY HEART❣❣❣❣❣❣❣❣
@ompawar9791
@ompawar9791 11 ай бұрын
wow
@DeepikaaSelvam
@DeepikaaSelvam 3 ай бұрын
Waiting for Strings Playlist !.. No one is talking about the String Concept!!!
@MOHAMMEDMOJAHID-rg8sc
@MOHAMMEDMOJAHID-rg8sc 3 ай бұрын
Me too
@JalalMujawar
@JalalMujawar 3 ай бұрын
Code for removing a node without knowing the head: public void deleteNode(ListNode node) { node.val = node.next.val; node.next = node.next.next; }
@AtulPal-i5s
@AtulPal-i5s 2 ай бұрын
Waiting for String Playlist
@HarishKumar-jm5bk
@HarishKumar-jm5bk Жыл бұрын
Striver can u please make series on binary numbers number theory and bit manipulation there is no video on youtube please make this video if possible
@dhikshitha7694
@dhikshitha7694 11 ай бұрын
Awesome video! In deletion of last/tail node in the base case if either the length is 0 or 1 we return null, but when length is 1 we should free the allocated memory that is delete head and then return nullptr right?
@MyAnish22
@MyAnish22 Жыл бұрын
@25:40 timestamp - we can also write prev->next = temp-> next? Also, if k==4 then tail gets deleted but what about indicating prev as the new Tail? Can understand, if any node pointing to nullptr is a tail then its fine.
@Shikaslad-s5f
@Shikaslad-s5f 3 ай бұрын
don't know what might be the issue but if k = n+1 where n = length of LL it is still removing the last element from LL Here is the code Node* removek(Node* head, int k){ if(head == NULL)return head; if(k==1){ Node* temp = head; head = head->next; delete temp; return head; } int count = 0; Node* prev = NULL; Node* temp = head; while(temp != NULL){ count++; if(count == k){ prev->next = prev->next->next; delete temp; break; } prev = temp; temp = temp->next; } return head; }
@omkarsawant9267
@omkarsawant9267 6 ай бұрын
Guys during Insertion kindly modify your node constructor or else you will get argument error. Modified code below-> class Node { public: int data; Node *next; public: Node(int data1, Node* nextNode = nullptr) { data = data1; next = nextNode; // argument added } }; Below Insert Node code--> Node* insertHead(Node* head, int val){ Node* temp = new Node(val, head); return temp; } int main() { vector arr = {2, 5, 8, 7}; Node *head = convertArr2LL(arr); head = insertHead(head, 18); print(head); return 0; }
@ARNAVGUPTA-s1m
@ARNAVGUPTA-s1m 2 ай бұрын
If we create a dummy node before head, we will not have to worry about edge cases. Just remember to return dummy->next.
@itsksujan
@itsksujan 6 ай бұрын
35:00 don't we have to update the head to point to the new node that is inserted at the head ?
@sonyshaw9964
@sonyshaw9964 6 ай бұрын
Indeed supreme quality article
@shivamswarnkar7763
@shivamswarnkar7763 22 күн бұрын
In the very last code which he has written we have to write while(temp.next.next not equal to null) instead of while temp.next not equal to null. If I am wrong, would be grateful for corrections.
@gyanendrasonkar3144
@gyanendrasonkar3144 9 сағат бұрын
I feel the condition is fine and safe to have. eg: case1) 1->null key = 1, ele= 2 if (head.val == key) return new Node(ele, head) works. 2->1->null Case 2) 1->2->null key =2, ele=3. temp =head; So , temp points to head, temp @1. (temp,head) 1 ----> 2->null if temp->next->data is same key( 2==2) , yes create a node, x = new Node(ele, temp->next) x 3---> 2---> null ^ | 1(temp,head) temp -> next = x; x 3---> 2---> null ^ | 1(temp,head) 1->3->2->null Another example::: 1-2-3-5-6-null key =5, ele 4 when we found the key, ( temp->next-data== key), stop here and add the node ^^^ head temp 1-----2-----3--------5---------6---null x = new Node(ele, temp->next) h temp x 1----2-----3 4------5----6--null ( remember temp next still pointing to 5 , can't draw ^^) temp -> next = x; h 1-2-3-4-5-6-null I hope it is cleared now...
@SanthoshaK-px8rq
@SanthoshaK-px8rq 5 ай бұрын
public Node DeleteK_ele(Node head, int k){ Node temp = head; if(k == 1){ temp = head.next; return temp; } int i=1; while(i
@AbhishekRanjan-wk7xp
@AbhishekRanjan-wk7xp 4 ай бұрын
but how will you handle the case when k>length of linked list
@AshokKumar-td2qo
@AshokKumar-td2qo 10 ай бұрын
Hey Striver you are my inspiration. Very thank you for LinkedList playlist ❤❤ Please suggest dbms in english video i can't understand hindi
@beaware70
@beaware70 Жыл бұрын
Great explaination sir❤❤❤❤
@vivekgautam9766
@vivekgautam9766 2 ай бұрын
Make a series on strings from basics to advance.
@vivekkumar841
@vivekkumar841 9 ай бұрын
awesomee lecture bhaiya!!!
@Student-j4u
@Student-j4u 5 ай бұрын
to delete kth element when cnt==k can we write prev=temp.next instead of prev=prev.next.next
@AnujTiwari-g8o
@AnujTiwari-g8o 2 ай бұрын
you are a star bro...🔥🔥🔥🔥🔥🔥
@doremon81072
@doremon81072 7 ай бұрын
loved it, Jai ho striver bhaiya
@Ravithasingh089
@Ravithasingh089 Жыл бұрын
Glad to be the First viewer brooooo🎉🎉🎉. Thank you so much for this quality content.!!
@bullymaguire2335
@bullymaguire2335 5 ай бұрын
is there a python playlist for linkedlist im unable to find it .
@Ayeshasingh720
@Ayeshasingh720 4 ай бұрын
so.... finally i m understanding LL🙂
@rohitkuttum3102
@rohitkuttum3102 3 ай бұрын
in delete tail remeber to free the head if (head->next==null) while using c++ . ignore java,python,js developers.
@ThakurIsGeek
@ThakurIsGeek 10 ай бұрын
good work i have learn alot from you
@alokkulkarni7854
@alokkulkarni7854 5 ай бұрын
when i tried to run the the code in vs code it showed error in many lines especially those where node was used as data type for function , can anyone clear why so ?
@saitejanedunoori5451
@saitejanedunoori5451 6 ай бұрын
great work and thank you THALA
@adebisisheriff159
@adebisisheriff159 9 ай бұрын
Thanks so much Striver!!!!
@junaidmetkari6365
@junaidmetkari6365 4 ай бұрын
waiting for string playlist🙂🙂
@khushisaraswat5826
@khushisaraswat5826 4 ай бұрын
Nice tutorials u have removed the need of such paid dsa courses....
@jainkokila2335
@jainkokila2335 2 ай бұрын
55:30 found is bool it cannot store 1 it can store true to solve our purpose
@HitanshuRathi-zz5vn
@HitanshuRathi-zz5vn 8 күн бұрын
Understood Thanks brother
@SurajKumar-ku1lg
@SurajKumar-ku1lg 7 ай бұрын
why we take for cnt =1 as increase by 1 and why not intialise prev as head as move on
@Dibyadipan
@Dibyadipan 2 ай бұрын
I have a small doubt in 3:48 where we are writing the code for removing the head of the linked list. the code snippet is as follows: private static Node removeHead(Node head) { if (head == null) { return head; } head = head.next; return head; } Here if we look at the first edge case where head==null is being tested. If i am not wrong that means the linked list is empty. so if the linked list is itself empty/having null value then it is obvious that removing the head will result in returning the null value right? And Striver said while explaining that if there is only one element too then the element behaves as both the head and the tail so removing the head will result in returning a null value...but here we are not checking that ie we are not checking if (head.next == null ) why is that so could anyone please explain me?
@SpeedBirb
@SpeedBirb Ай бұрын
because if head->next is null, we are setting head=head->next after the if statement, which will make head=NULL, and return null. So there is no need to check for head->next
@mma-dost
@mma-dost 9 ай бұрын
The question which was deleting the node whose pointer is given to you not the linked list head pointer that question is not covered right ? Its in the sheet last question Singly LL
@albela7434
@albela7434 7 ай бұрын
greatttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt lecture i ever watched
@ShubhamKumar-me7py
@ShubhamKumar-me7py 6 ай бұрын
hey can we do dsa together
@agnivadutta969
@agnivadutta969 9 ай бұрын
In Java, removing head program, isn't the temp variable needs to be set null before garbage collection?
@TS-oj3vd
@TS-oj3vd 8 күн бұрын
25:31 what if k=2? code will break giving error. prev is still null.
@shivanisahu8075
@shivanisahu8075 26 күн бұрын
in java how to print full ll with changes when we return head so they print vlue of head only plz tell me how to print new ll
@pavanisri0512
@pavanisri0512 9 ай бұрын
Can you do in python also
@salihedneer8975
@salihedneer8975 Жыл бұрын
how many videos will be there
@NewtonVarma
@NewtonVarma 4 ай бұрын
Hey @takeUforward striver please upload string lectures,
@himanshukaushik9223
@himanshukaushik9223 10 ай бұрын
Anyone submitted last 2 questions on coding ninja it show compilation error
@hardikpatel352
@hardikpatel352 6 ай бұрын
Thanks a lot striver, understood
@vilen2685
@vilen2685 10 ай бұрын
Thankuhh sir for giving code in java !!!!
@simranmaity7252
@simranmaity7252 10 ай бұрын
Can you please provide the code ..
@siyonabansal6703
@siyonabansal6703 5 ай бұрын
why dont we take k-1 instead of previous in kth element
@algorithm_based
@algorithm_based 26 күн бұрын
in some case if the head is not given what we can do ?
@amanasrani6405
@amanasrani6405 2 ай бұрын
Thank You so muchhhhh ❤❤❤❤❤🙏🏻, understood
@Vishu2-3
@Vishu2-3 8 ай бұрын
27:54 prev -> next = temp -> next; free(temp); correct or not?
@BadalJena-oh6qu
@BadalJena-oh6qu 3 ай бұрын
inserting at kth positition 38:00
@ShivamKumar-oj7ud
@ShivamKumar-oj7ud Ай бұрын
in deletion of value...it will not be able to delete multiple values of list
@satyamrath6818
@satyamrath6818 6 ай бұрын
Can you please attach the test link as well for practice. Thanks
@jevinkardani
@jevinkardani 8 ай бұрын
can someone explain what is the difference b/w NULL and nullptr ?
@bharanitharan.m1158
@bharanitharan.m1158 3 ай бұрын
Hey, When you want to delete 1st position of linkedlist in at any position you got wrong answer
@purvshah4260
@purvshah4260 Жыл бұрын
god level explaination
@36nchiranjeevi53
@36nchiranjeevi53 11 ай бұрын
Great explanation
@DevashishJose
@DevashishJose 8 ай бұрын
Thank you so much.Understood
@darshilmodi6851
@darshilmodi6851 5 ай бұрын
When is the string playlist releasing ?
@AniketKumar-hf2bo
@AniketKumar-hf2bo 7 ай бұрын
thnx for amazing video ❤❤❤👌👌👍👍👍👍
@radha7492
@radha7492 10 ай бұрын
sir while deleting the Element using its value like given example mein jab hum 12,5,8,7 mein se 12 ko remove krenge using removesEl(head,12) toh error aa rha h (bhot sari random values dikha rha h), I need help, i checked my code more than 8 times but error nhi resolve ho rha, plss help someone
@anuragprasad6116
@anuragprasad6116 9 ай бұрын
code to post kr de behn
@TON-108
@TON-108 10 ай бұрын
Understood, Thanks!
@ishita8305
@ishita8305 5 ай бұрын
please upload the strings playlist sir..
@deepakbhatt555
@deepakbhatt555 11 ай бұрын
nicely explained !
@anshukumari6226
@anshukumari6226 9 ай бұрын
Thanks for the video!
@supernova4467
@supernova4467 Жыл бұрын
idk no why i cant do problem solving i can understand dsa topics pretty easily but cp feels very hard to me like this year codevita questions like orchard , vip cafe , maze runner i could not figure out them im really ashamed of myself
@VishalGupta-xw2rp
@VishalGupta-xw2rp Жыл бұрын
You start with A20J Ladder
@NazeerBashaShaik
@NazeerBashaShaik 7 ай бұрын
Understood, thank you
L3. Introduction to Doubly LinkedList | Insertions and Deletions
1:04:07
take U forward
Рет қаралды 184 М.
L1. Introduction to LinkedList | Traversal | Length | Search an Element
45:17
За кого болели?😂
00:18
МЯТНАЯ ФАНТА
Рет қаралды 3 МЛН
Don't underestimate anyone
00:47
奇軒Tricking
Рет қаралды 15 МЛН
How Much Tape To Stop A Lamborghini?
00:15
MrBeast
Рет қаралды 210 МЛН
How To Choose Mac N Cheese Date Night.. 🧀
00:58
Jojo Sim
Рет қаралды 88 МЛН
Making an Algorithm Faster
30:08
NeetCodeIO
Рет қаралды 147 М.
I Solved 1583 Leetcode Questions  Here's What I Learned
20:37
ThePrimeTime
Рет қаралды 736 М.
Arpit Bhayani talks about real engineering for 1 hour straight
1:16:23
L4. Reverse a DLL | Multiple Approaches
18:30
take U forward
Рет қаралды 97 М.
do you know how "return" works under the hood? (are you SURE?)
5:08
Complete Dynamic Programming Practice - Noob to Expert | Topic Stream 1
3:50:43
L5. Add 2 numbers in LinkedList | Dummy Node Approach
14:48
take U forward
Рет қаралды 115 М.
За кого болели?😂
00:18
МЯТНАЯ ФАНТА
Рет қаралды 3 МЛН