Started this course back in june 2022 , now have reached 120th video but simulatenously revising concepts, again and this time understading his videos in more depth and using it as a revision to improve TC of my solutions.
in 1st code of loop detection, there is condition that slow and fast is not equal to null. if we have single node with no cycle, initially slow and fast both point to it. At time of entering while loop , both slow and fast pointing to head and not equal to null. So it will enter the loop, so after the 1st iteration, fast = null and slow = null. Now in loop itself it will check that slow = fast which is true because both slow and fast are null. So in this case it will give o/p as loop is present but loop is not present. So code will not run correctly for one node
Bro please check if this code runs in your compiler or not, because the loop is present statement is not running in my compiler. #include #include #include using namespace std; class Node{
public: int data; Node * next; Node(int data){ this->data = data; this->next = NULL; } }; void insertAtHead(Node* &head, int d){ //creating new node which then will be our first node-> Node* node2 = new Node(d); node2->next = head; head = node2; } void insertAtTail(Node* &tail, int d){ //creating new node which then will be our first node-> Node* node2 = new Node(d); tail->next = node2; tail = node2; } void insertAtPosition(Node* & tail, Node* & head, int position, int d){ //Using below condition we are inserting the given element at start, // and then updating the head-> if(position == 1){ insertAtHead(head, d); return; } Node* temp = head; int count = 1; while(count < position-1){ temp = temp->next; count++; } //if we are inserting at the end, then this condition will update the tail-> if(temp->next == NULL){ insertAtTail(tail, d); return; } //Creating a node for d-> Node* nodeToInsert = new Node(d); nodeToInsert->next = temp->next; temp->next = nodeToInsert; } void print(Node* & head){ Node* temp = head; while(temp != NULL){ cout
Bhaiya the explanations are too good. Just an FYI, floyd wale me loop detection me base case me head.next != null bhi check karna hoga as if we have a normal linkedList with just one node, uske lie bhi cycle bolega. kyuki apn if k andar jayenge fir dono slow aor fast ko next kar denge that is null and fir compare karne pe bolega ki loop hai bhaiya. I know its just that aap vscode me kara rhe the islie miss ho gaya. Meko gfg me error aya solve karne me fir mila :D
44:25 At this moment I finally realized why rest of the distance in the loop is A. Prior to that, I was really perplexed with how you found that out. Understood it Not because of how you spoke in that moment but noticed that A = [ (k no. of cycles)*(each Cycle) ] - B . which is also the rest of the distance.
yes , A is not the distance of each cycle C its some K times we are covering that C and finally we found out the meeting point of fast and slow ( the remaining becomes A)
Approach 2. Using Floyd cycle detection , we save time complexity compared to approach 1. Also, we are using slow and fast concept in this method. If fast==slow then Linked List is circular.
Most appreciated about this Course is first how he tell the approach And then write alogirthm and then code which is a approach a engineer have to follow.
Bro please check if this code runs in your compiler or not, because the loop is present statement is not running in my compiler. #include #include #include using namespace std; class Node{
public: int data; Node * next; Node(int data){ this->data = data; this->next = NULL; } }; void insertAtHead(Node* &head, int d){ //creating new node which then will be our first node-> Node* node2 = new Node(d); node2->next = head; head = node2; } void insertAtTail(Node* &tail, int d){ //creating new node which then will be our first node-> Node* node2 = new Node(d); tail->next = node2; tail = node2; } void insertAtPosition(Node* & tail, Node* & head, int position, int d){ //Using below condition we are inserting the given element at start, // and then updating the head-> if(position == 1){ insertAtHead(head, d); return; } Node* temp = head; int count = 1; while(count < position-1){ temp = temp->next; count++; } //if we are inserting at the end, then this condition will update the tail-> if(temp->next == NULL){ insertAtTail(tail, d); return; } //Creating a node for d-> Node* nodeToInsert = new Node(d); nodeToInsert->next = temp->next; temp->next = nodeToInsert; } void print(Node* & head){ Node* temp = head; while(temp != NULL){ cout
hmm you're right, but we can remove this logn complexity by using an unordered_map instead of a normal one... It's implementation is different than the normal one. So the operations take constant time.. There's a video about it, do watch it... ua-cam.com/video/gUrfXZ0hqoA/v-deo.html
It's my humble request to everyone watching the vidoes , please do like his video because he is putting his effort and providing us such a valuable content , that too free of cost, so we can atleast appreciate him by pressing the like button. I hope everyone uderstands what i am trying to convey. 👍👍
Thank you sir, for providing such a explained lecture on this topic. Because of it, I was able to solve detect cycle in a LL, which I was trying for last 2 hours.
Yee baaatttt 🔥💥 Har dinn aapke liye ijjat badte hi jaa rhi he , bhagwan na ban jao DSA ke 🔥😂 Bhaiya plz *"5 Month Internship Strategy Series"* laaO... 2nd year walo ke liye with your DSA Busted course as resource 😃🤩
this video series iam watching is cleraing my concepts of linked list it is a good coding channel i ever seen. Also great lectures which are helping in clearing my concepts .
Present Josh high bhaiya mujhe bohat daar lagta h placements ka khudse logic nhi soch pata hu but aap jo bhi padhate ho sab smj ata h ,pta nhi ky hoga mera 6 mahine me placements h
If someone is here for the Java code, then we can use HashSet instead of HashMap. (Note: Considering all the elements are unique, if not then use HashMap) public class Solution { public boolean hasCycle(ListNode head) {
Thanks is a very small word to tell you Love bhai ♥️ We won't let u down Love bro. Shayad seekhna delay hoga, par seekenge saare pakkaaa 🌀 *Srinivas from AP, reporting bhai!* 🚀
majaa aa gaya previously when bhaiya writes code i have to check again n again to write code but now i can understand code clearly when bhaiya write it and i am able to write code in one goo..
sir your videos are very helpful for me thankyou love bhaiya you had done a great job of providing free content which provide knowledge more than the paid course
@lovebabbar Bhaiya yrr , apne map to sikhaya hi nhi hume kese ayega maps ka concept. hashmap ki video 80 h or apne yahi use karwa diya h concept nhi clear h bass upr upr se hi pata ki haa map bhi kuch hota rest I totally appreciate your efforts in this course this course is worth more than paying thousands in paid courses.
Homework Question: Q : Remove Duplicates from an Unsorted Linked list. Node *removeDuplicates(Node *head) { if(head==NULL){ return NULL; } map visited; Node* temp = head; Node* prev = NULL; while(temp!=NULL){ if(visited[temp->data]==true){ prev->next = temp->next; delete temp; temp = prev; }else{ visited[temp->data] = true; } prev = temp; temp = temp->next; } return head; } It's correct and working code , but CodeStudio shows error regarding map data stucture i used in this code. But its working fine in my VSCode as i included map library.
bhaiya floyd wale m agr single node hui ar uska next usi ko point nhi kr rha...to aapne jo code btaya us case m to true return krega ...qki fast=fast->next(NULL) hoga ar slow=slow->next(NULL)...ar dono equal h..so return 1 krega ...but return false krna chaiye na.....iske liye if(head==NULL|| head->next==NULL) return 0; krna pdega..
i think remove loop is the most hardest question on the linked list as we have to find the first element of the loop then we will implement the logic to remove the loop
video was really cool and amazing but I could not use flyod's loop detection method to find first element of loop that's why i had to do it by using map and complexity went a little bit bad from O(1) to O(n) but your method of flyod's loop detection went wrong
one little suggestion in the program, just add else return false; after the if statement where we check fast->next is NULL or not, inside the while loop.
bhaiya ji agar intersection pointer me NULL aa gya (no loop present) then we access a node with null pointer so give a run time error , if this error is remove then we added a condition after calling floyedsDetection() fuction inside the function of getstartingnode() -->>>if(intersection == NULL) return NULL; thanku bhaiya ji (i m correct or not)
Started this course back in june 2022 , now have reached 120th video but simulatenously revising concepts, again and this time understading his videos in more depth and using it as a revision to improve TC of my solutions.
😊😊😊😊😊😊😊😊😊😊😊
in 1st code of loop detection, there is condition that slow and fast is not equal to null. if we have single node with no cycle, initially slow and fast both point to it. At time of entering while loop , both slow and fast pointing to head and not equal to null. So it will enter the loop, so after the 1st iteration, fast = null and slow = null. Now in loop itself it will check that slow = fast which is true because both slow and fast are null. So in this case it will give o/p as loop is present but loop is not present. So code will not run correctly for one node
make it a do while loop instead, then it will run
Bhaiya mathematical proof of Floyd algo is op😎.. Finally got the point why we are actually doing this..And the way you explained in super awesome
After watching your videos, it feels that the most easiest part of coding after printing "Hello World" is Linked List..😄😄😄😄
thank you for being consistent and delivering the high-quality course.
Bro please check if this code runs in your compiler or not, because the loop is present statement is not running in my compiler.
#include
#include
#include
using namespace std;
class Node{
public:
int data;
Node * next;
Node(int data){
this->data = data;
this->next = NULL;
}
};
void insertAtHead(Node* &head, int d){
//creating new node which then will be our first node->
Node* node2 = new Node(d);
node2->next = head;
head = node2;
}
void insertAtTail(Node* &tail, int d){
//creating new node which then will be our first node->
Node* node2 = new Node(d);
tail->next = node2;
tail = node2;
}
void insertAtPosition(Node* & tail, Node* & head, int position, int d){
//Using below condition we are inserting the given element at start,
// and then updating the head->
if(position == 1){
insertAtHead(head, d);
return;
}
Node* temp = head;
int count = 1;
while(count < position-1){
temp = temp->next;
count++;
}
//if we are inserting at the end, then this condition will update the tail->
if(temp->next == NULL){
insertAtTail(tail, d);
return;
}
//Creating a node for d->
Node* nodeToInsert = new Node(d);
nodeToInsert->next = temp->next;
temp->next = nodeToInsert;
}
void print(Node* & head){
Node* temp = head;
while(temp != NULL){
cout
@@aditya_0524 try to run this in online compiler as it is an infinite loop
Mathematical proof of Flyod's Loop detection was Awensome
@@rapidtech9592 yup dude you are fucking right
Bhaiya the explanations are too good.
Just an FYI, floyd wale me loop detection me base case me head.next != null bhi check karna hoga as if we have a normal linkedList with just one node, uske lie bhi cycle bolega. kyuki apn if k andar jayenge fir dono slow aor fast ko next kar denge that is null and fir compare karne pe bolega ki loop hai bhaiya.
I know its just that aap vscode me kara rhe the islie miss ho gaya.
Meko gfg me error aya solve karne me fir mila :D
yes bro you are absolutely right. thanks for telling the error
hey, if you don't mind can you share the GFG code?
+1
44:25 At this moment I finally realized why rest of the distance in the loop is A. Prior to that, I was really perplexed with how you found that out. Understood it Not because of how you spoke in that moment but noticed that A = [ (k no. of cycles)*(each Cycle) ] - B . which is also the rest of the distance.
And i got that better after raeding ur cmmnt...😅
what if value of k =0.5??
BUT IN REST OF THE DISTANCE WE DONT HAVE TO INCLUDE K NUMBER IF CYCLES. I STILL DIDNT GOT, PLZ CLEAR IT,
yes , A is not the distance of each cycle C
its some K times we are covering that C and finally we found out the meeting point of fast and slow ( the remaining becomes A)
Great lectures🔥🔥.
Unlike other inconsistent youtubers who only claim to complete a course in this this time.
By far the best course on DSA , ty for your consistency and hard work .
You have pretty much covered everything in linked lists , salute to you hard work
Today everyone has made education a business but sir you have given this course for free ,it is much better than paid courses. Thank you sir❤
kitne paid course leliye tune?
1. map visited; is used to detect Loop in LL.
Approach 2. Using Floyd cycle detection , we save time complexity compared to approach 1.
Also, we are using slow and fast concept in this method.
If fast==slow then Linked List is circular.
you are really a great person who is helping us in such a nice way . Please keep it up.🥰🥰
Most appreciated about this Course is
first how he tell the approach
And then write alogirthm and then code which is a approach a engineer have to follow.
at 35:55 slow is increasing by 1 and also intersection increasing by 1 so this is a infinite loop condition . here both are increased by 1.
Crrct even I got that after dry run on different example
14:24 I think TC will be O(nlogn), log(n) extra because of insertion in map. It would be O(n) if we would have used an unordered_map instead.
+1
Bro please check if this code runs in your compiler or not, because the loop is present statement is not running in my compiler.
#include
#include
#include
using namespace std;
class Node{
public:
int data;
Node * next;
Node(int data){
this->data = data;
this->next = NULL;
}
};
void insertAtHead(Node* &head, int d){
//creating new node which then will be our first node->
Node* node2 = new Node(d);
node2->next = head;
head = node2;
}
void insertAtTail(Node* &tail, int d){
//creating new node which then will be our first node->
Node* node2 = new Node(d);
tail->next = node2;
tail = node2;
}
void insertAtPosition(Node* & tail, Node* & head, int position, int d){
//Using below condition we are inserting the given element at start,
// and then updating the head->
if(position == 1){
insertAtHead(head, d);
return;
}
Node* temp = head;
int count = 1;
while(count < position-1){
temp = temp->next;
count++;
}
//if we are inserting at the end, then this condition will update the tail->
if(temp->next == NULL){
insertAtTail(tail, d);
return;
}
//Creating a node for d->
Node* nodeToInsert = new Node(d);
nodeToInsert->next = temp->next;
temp->next = nodeToInsert;
}
void print(Node* & head){
Node* temp = head;
while(temp != NULL){
cout
hmm you're right, but we can remove this logn complexity by using an unordered_map instead of a normal one... It's implementation is different than the normal one. So the operations take constant time..
There's a video about it, do watch it...
ua-cam.com/video/gUrfXZ0hqoA/v-deo.html
+1
Me to interviewers : Hello Jee! Kaise ho saare 😎
Interviewer : isko to Bangalore le jana padega
It's my humble request to everyone watching the vidoes , please do like his video because he is putting his effort and providing us such a valuable content , that too free of cost, so we can atleast appreciate him by pressing the like button. I hope everyone uderstands what i am trying to convey. 👍👍
Thank you sir iss course ke liye....
Sir greedy kab se start kroge??
Lecture 47 completed on 26 June 2024.
Thank you sir, for providing such a explained lecture on this topic. Because of it, I was able to solve detect cycle in a LL, which I was trying for last 2 hours.
Yee baaatttt 🔥💥
Har dinn aapke liye ijjat badte hi jaa rhi he , bhagwan na ban jao DSA ke 🔥😂
Bhaiya plz *"5 Month Internship Strategy Series"* laaO...
2nd year walo ke liye with your DSA Busted course as resource 😃🤩
Nice explaination.......
int rating=0;
while(explaination != Superb){
rating++;
}
28:50 piche lakshya be like : ye babber kab lecture complete karega and muje chair milegi!
this video series iam watching is cleraing my concepts of linked list it is a good coding channel i ever seen. Also great lectures which are helping in clearing my concepts .
Present
Josh high bhaiya mujhe bohat daar lagta h placements ka khudse logic nhi soch pata hu but aap jo bhi padhate ho sab smj ata h ,pta nhi ky hoga mera 6 mahine me placements h
Bro placement hua??
Thank you sir
We are really motivated by the amount of efforts you put 🙏
maja aa rha hai bhaiya, mene jab syllabus me pdha tha LL to bahot tough lga tha, but ab to baccho wali game lgta hai ; )
Bhaiya course is going amazing 👍👍👍👍👍
Placement ki majboori mai shuru kra tha pr abb mja aane lga hai 😅😅😂😂
Lecture47: Detect & Remove Loop in Linked List [Approach Discussion + Optimised Implementation]
If someone is here for the Java code, then we can use HashSet instead of HashMap. (Note: Considering all the elements are unique, if not then use HashMap)
public class Solution {
public boolean hasCycle(ListNode head) {
if(head == null || head.next == null)
return false;
HashSet vis = new HashSet();
ListNode temp = head;
while(temp != null){
if(vis.contains(temp))
return true;
vis.add(temp);
temp = temp.next;
}
return false;
}
}
You are the best teacher 🔥🔥
This lecture is very awesome 👍
Thanks is a very small word to tell you Love bhai ♥️
We won't let u down Love bro.
Shayad seekhna delay hoga, par seekenge saare pakkaaa 🌀
*Srinivas from AP, reporting bhai!* 🚀
majaa aa gaya previously when bhaiya writes code i have to check again n again to write code but now i can understand code clearly when bhaiya write it and i am able to write code in one goo..
Thank you Bhaiya,
We are really motivated by the number of efforts you put 🙏
yaar kya lecture tha mza agaya bhai
Detect & Remove Loop in Linked List [Approach Discussion + Optimised Implementation]
Maza aa gaya bhaiya .....mehnat safal hui aapka meri taraf se ..sab samj aa gaya abhi ...5 tarike dhundhne jaa raha hu ...Ly ♥️
sir your videos are very helpful for me thankyou love bhaiya
you had done a great job of providing free content which provide knowledge more than the paid course
Thank you vaiya... you have explained all the concepts very well.... your course is zero to HERO wala hain....
@lovebabbar
Bhaiya yrr , apne map to sikhaya hi nhi hume kese ayega maps ka concept.
hashmap ki video 80 h or apne yahi use karwa diya h concept nhi clear h bass upr upr se hi pata ki haa map bhi kuch hota
rest I totally appreciate your efforts in this course this course is worth more than paying thousands in paid courses.
************NOTE*********
remove linked list k 3 methods mile mujhe
1)floyds algo
2)maps
3)distance comparison
or 2 mile to batao na
Thank you bhaiya for making this video in deep
thank you apne is ko 15 min mei nhi smjhaya..
following this course from very first lecture
💌🍀❤
Love u sir, m abhi consistent nahi ho paya pr aaj se fir continue karra hu,
aap fir bhi consistent ho😔😇
maja azagaya bhaiya...watching it after 1 year of making and this playlist is golden
Homework Question:
Q : Remove Duplicates from an Unsorted Linked list.
Node *removeDuplicates(Node *head)
{
if(head==NULL){
return NULL;
}
map visited;
Node* temp = head;
Node* prev = NULL;
while(temp!=NULL){
if(visited[temp->data]==true){
prev->next = temp->next;
delete temp;
temp = prev;
}else{
visited[temp->data] = true;
}
prev = temp;
temp = temp->next;
}
return head;
}
It's correct and working code , but CodeStudio shows error regarding map data stucture i used in this code.
But its working fine in my VSCode as i included map library.
I really appreciate your efforts and dedication to making such awesome content for us. Much obliged to you.
I have learned basic ds in c language only,can I follow this course for problem solving?
@Ayusman Arya I started yesterday and thanks....
bhai yee wala video best tha poora ka poora samaj mai agaya
Bhaiya ek question ki list bhi dedo na topics wise taki practice kar paye please please please
this course is more than inouf and love babbar bhaiya put the maximum in this course and far better than paid course❤❤❤❤❤💖💖
aaj ka kota pura ab kal dekho ga bye lage raho bhaiye effort!!!
bhaiya puri mehnat dekh rhi h thank u so much
bhaiya floyd wale m agr single node hui ar uska next usi ko point nhi kr rha...to aapne jo code btaya us case m to true return krega ...qki fast=fast->next(NULL) hoga ar slow=slow->next(NULL)...ar dono equal h..so return 1 krega ...but return false krna chaiye na.....iske liye
if(head==NULL|| head->next==NULL)
return 0;
krna pdega..
Thanks, bhaiya for explaining this question in so much depth and detail...Hats off to you bhaiya
i think remove loop is the most hardest question on the linked list as we have to find the first element of the loop then we will implement the logic to remove the loop
i am not able to understand 33:30 ; you said a+b = K*c : then how just a+b = c, if K>1 then ? please explain !
Very good explanation 😄😄 bhaiya Aaj to swad hi aa gya linked list ki 😋😋
Love you babbar bhaiya
thanku bhai , placement lag gyiii 😊😊😊
chata toh 15 min m kr skate the kise or k playlist ..... pr smhj chi aata ...isle love babber❤🔥 p. Maya
Osm question and answer 😊😊
thanks bhai for the series, i never followed a series like dis . love you bhai
video was really cool and amazing but I could not use flyod's loop detection method to find first element of loop that's why i had to do it by using map and complexity went a little bit bad from O(1) to O(n)
but your method of flyod's loop detection went wrong
Ye question to bhai alag level ki bhasad haai pr maja aata hai krne mein !
Gajab Ki Video hai bhaiya Maza Ahhyga👌👌👌👌
yar babbar bhai yea na pocha kro k video kesi lgi.......level hi ho gya really mtlb best best best
thks bhaiya for a best DSA series for student
thankyou so much bhaiya I undersood full linked list
from 40 to 47 it was the most interesting episode
Aa gya hu bhaiya.... Iske baad haar roj hi video ayega lag raha hai.....❤️❤️❤️❤️❤️❤️❤️
Thanks bhaiya.... For such amazing 😍😍 content ....
bhaiya, I really appreciate your efforts . god bless you. ❤️
Thanks bhaiya for explaining the mathematical Proof of Floyd cycle detection the concept is crystal clear now.
op video seiously 🔥ise kehte hai genuine content
finally realized how to find starting point of the cycle
....thanks a lot
easy to understand..because you teach so well....kudos to you bhaiya🙏🙇🙇
bhaiya 5 month internship series for 2nd year student with DSA busted course as resource par video bana do
this is what we call it has explanation 🔥🔥
Thanks big b finally coding is looking sooooo easy because of you ....
dekh rhe h bhaiya puri videoes don't worry about that full on josh ke sath tier-3 vale har nhi manenge
Bhaiya
Your way of explaining concepts are very amazing......
subha se baar baar you tube khol ke dekh raha th akab aayegi video ....... or ab aa gyi
bhaiya thank you from bottom of my heart
you put real effort for us(along with us) of course!!
😄
Bhaiya upload a video on, main channel, about the further course, how long it will take more And all!
love you bhaiya , hame bhot help mil rahi hai in videos se !!
Attendance marked bhaiya ji both for OS & DSA..... hum saab champ banenge ..... barabar banenge...... Lots of lOve
Bohat mehnat kartay hen ap bhayia salute ha 🔥🔥🔥
30:42 lakshay bhaiya is busy with his nose !!😂😂😂 btw thank you so much to both of you for providing us with such great content. !!❤️❤️
one little suggestion in the program, just add else return false; after the if statement where we check fast->next is NULL or not, inside the while loop.
Best explanation of such a deep concept fr🐐
hnji bhaiya, smjh aa gya badhiya se, agli video shuru kr rha hoon, bss vishwas bnaye rkhna krdoonga khtm aaj😅👍
bhaiya ji agar intersection pointer me NULL aa gya (no loop present) then we access a node with null pointer so give a run time error , if this error is remove then we added a condition after calling floyedsDetection() fuction inside the function of getstartingnode() -->>>if(intersection == NULL) return NULL; thanku bhaiya ji (i m correct or not)
wah bhaiyaa mza a gya smj aya sub ekdum badiya tarike se❤💯👍👍
Thank You So Much BHRATA SHREE !!!!
Bhaiya really Nice and amazing explanation , Concept became crystal clear.....
thank you bhaiya for such an awesome course ... nsit'25 batch....
one of the best content on linked list
11:26 i laughed so damn hard "hogaya pagal"🤣🤣
maja aarhi h bhaiya high lvl content mil rha h aur kya chahie bhaiya
Lakshay bhaiya spotted background floor pr 😂🤣
Thank you for all your efforts.
I am literally 1 month behind 😕
Kudos to you! You are 3 months ahead of me :)