I have never seen a guy explaining DSA so easily. He is like a gem for me, I discovered this channel couple a of days ago and it is so underrated. I hope this channel will gain popularity very soon cause' this channel is way better than other channels like Apna College and Baber.
Yes it will work if we take three time the speed or even n time the speed n > 1 We can think of the proof as two cars moving one chasing other and their relative velocity being directed towards one of the other then surely they will meet if the track is circular or else the fast car would reach end first
@coderArmy bhaiya ye to O(N) space me bhi accept ho gaya tha to fir aapko kese pata chala ki O(1) space complexity vala bhi solution exist karta hoga uske upar research karni chahie? ? kyunki soluiton accept hone ke baad to mud ke kon hi que ko dekhta hai vapas
Bhai if we don't care about data then it is also working in ##detecting a loop Node *temp=head; int c=0; while(temp){ temp->data=-1; temp=temp->next; if(temp){ if(temp->data==-1){ c=1; break; } } } if(c==1) return 1; else return 0;
Sir mujhay aik question poochna hay wo ye kay Jab ham ne time complexity of detecting loop in lonked list nikali hay tab you said k 1+2+3+...n krein gay tou we will have order of n² How n² I thinking i am lacking in one of concepts Can u please clear my question
dekho nested loop hai kyuki curr pointer null tk ja rha hai mtb O(N) and uske ander check fn bhi size of vector tk ja rha hai mtb null tk O(N) dono O(N^2) jb loop linear hoti hai tb add krte hai O(N)+O(N)=O(N) and nested mai O(N) * O(N)=O(N^2)
remove loop in linked list class Solution { public: // Function to remove a loop in the linked list. void removeLoop(Node* head) { Node *slow = head, *fast = head; while (fast != NULL && fast->next != NULL) { slow = slow->next; fast = fast->next->next; // Detect if there's a loop if (slow == fast) { // Loop detected if (fast == head) { // If the loop starts from the head node itself while (fast->next != head) fast = fast->next; fast->next = NULL; } else { // If the loop starts from some middle node slow = head; while (slow->next != fast->next) { slow = slow->next; fast = fast->next; } fast->next = NULL; } return; // Loop removed successfully } } } };
Last home work solution:- class Solution { public: //Function to remove a loop in the linked list. void removeLoop(Node* head) { // code here // just remove the loop without losing any nodes if(head==NULL ||head->next==NULL){ return; } Node *fast=head; Node *slow=head; while(fast!=NULL &&fast->next!=NULL){ fast=fast->next->next; slow=slow->next; if(slow==fast){ slow=head; while(slow!=fast){ slow=slow->next; fast=fast->next; } while(fast->next!=slow){ fast=fast->next; } fast->next=NULL; return; } } } };
New year ka josh thanda hgya hai👀
No bhaiya
bhaiya nhi hoga thanda ab kabhi 🤩
nhi hoga
bhaiya ek course launch kro motivation ka aur uska nam rakh na Aasaan hai 😂
yeah bro
Aaj ke lacture ka sab kuch chamak gaya Rohit Bhaiya
Thank-you so much..............
itne verities of solution dene bale bhaiya ji ko sat sat naman
Rhohit Sir kmal ker dia.Thank you soo much.
Done Bhaiya... Day 120/180 ✅
I have never seen a guy explaining DSA so easily. He is like a gem for me, I discovered this channel couple a of days ago and it is so underrated. I hope this channel will gain popularity very soon cause' this channel is way better than other channels like Apna College and Baber.
facts bro he is a gem
Love from rudraprayag ❤❤
Bhaiya aapka explanations bahut badhiya hai .sidha dimaag me hit karta hai. Chamak! gaya pura concept chamak gaya😊.
Yes it will work if we take three time the speed or even n time the speed n > 1
We can think of the proof as two cars moving one chasing other and their relative velocity being directed towards one of the other then surely they will meet if the track is circular or else the fast car would reach end first
Sir aapka paid course hona chahiye tha ❤
Itna acha mene kisi aur ko nahi dekha padhate hue
True
due to trip i distracted about one week .now i am on the way of waching every video every day.thank you bhaiya
51:50 tk bahoot ache se chamak gayabhaiya thank you so much>>>1000
chamak gaye sare questions .. thank you bhaiya ji
chamak gya hai acche se thankyou bhaiya ji love u 😘😘
Great video...
Your teaching is just phenomenal
Sir aap ki videos sy bohot faida ho raha hai
chamak gaya guruji😍
Awesome lecture Bhaiya
Jai shree ram ❤️ ekdum ache se chamak Gaya 👍🏻
Sir such a great explanation..... from naive to full optimize approach❤ thank you so much for same❤❤
Perfectly Explained 🔥🔥
Bhaiya khatarnak solution the ekdam basic se baap level 🥳🥳
Bhiya u have amazing talent to understanding any topic ❤
bhaiya mathematical proof gajab tha
next level thinking
chamak gya sirrrrrrrrrrrrrrrrrrrr
❤🔥
bhai ye question karke maja aa gaya
Sab chamak Gaya bhaiya ❤❤
10:51 chamak gya❤
Chamak gaya bhaiya ji
Awesome lecture
you nailed it
Chamak gya bhaiya , dsa ab halwa hai ❤
chamak gaya bhaiya sab
Good morning bhaiya ❤❤
1:07:37 Homework
void removeLoop(Node* head)
{
// code here
// just remove the loop without losing any nodes
Node *slow = head, *fast = head, *prev = NULL;
while(fast->next && fast->next->next){
prev = slow;
slow = slow->next;
fast = fast->next->next;
if(slow == fast){
slow = head;
while(slow != fast){
prev = fast;
fast = fast->next;
slow = slow->next;
}
prev->next = NULL;
return;
}
}
}
bhaiya achhe se chamak gya h
chamak gaya bhayia
chamak gaya bhaiya😁
chamak gaya bhaiya
Rohit bhaiya padhae aur nhi chamke aisa ho skta h kya❤❤love u bhiya ji
Haan Ji Bhaiya Good Morning ❤❤
Good morning bhaiya ji❤
Length of loop
Node *slow = head, *fast = head;
while(fast && fast->next)
{
slow = slow->next;
fast = fast->next->next;
if(slow == fast)
{
int count = 0;
slow = fast->next;
while(slow != fast)
{
count++;
slow = slow->next;
}
return count+1;
}
}
class Solution
{
public:
//Function to remove a loop in the linked list.
void removeLoop(Node* head)
{
// code here
bool flag=0;
Node *slow=head,*fast=head;
while(fast!=NULL&&fast->next!=NULL){
slow=slow->next;
fast=fast->next->next;
if(slow==fast){
flag=1;
break;
}
}
if(flag==1){
Node*temp=head;
while(temp->next!=slow->next){
slow=slow->next;
temp=temp->next;
}
if(temp!=slow)
slow->next=NULL;
else{
while(slow->next!=temp){
slow=slow->next;
}
slow->next=NULL;
}
}
// just remove the loop without losing any nodes
}
};
As when temp ka next will equal to slow ka next then do baate hongi ki ya toh temp and slow same node par hai ya different node pe
maja aagya bhaiya ,
Chamak gya🎉
Chamak gyaa bhaiya 😄
Chamak gya bhaiya
46:30= Yes , it will still work
no it won't work bcoz slow ke sath match karne se pahle usse bhi aage nikal jaega , take different different number of nodes inside cycle
Bro u r 🔥🔥❤😊
fast and slow pointer sahi sa chamak gaya
Thanks bhaiya...❤🎉
chamak gaya😎😎😎😎
Good morning ❤
chamak gaya hai bhaiya
Suprabhat Bhaiya..
bhaiya chamak geya
Good Morning Bhyia 16:15 Kar sakte ho bhyia Bilkul aapka huq h
16:15 bhaiya ise bhi jyada bezzati karo hamari🤣🤣
15:50 do more vaiya :')
H/W=
public:
//Function to remove a loop in the linked list.
void removeLoop(Node* head)
{
// code here
// just remove the loop without losing any nodes
unordered_mapvisited;
Node *curr=head;
Node *address=NULL;
while(curr)
{
if(visited[curr]==1)
{
address=curr;
break;
}
visited[curr]=1;
curr=curr->next;
}
if(curr==NULL)
return;
curr=address->next;
while(curr->next!=address)
curr=curr->next;
curr->next=NULL;
}
slow and fast chamak chuka hai asman mein
Bhut acche se chamak rha hai, ab lg rha hai hm baap coder bn rhe hain 😅
Bhaiya ne bail 🐂 buddhi bola 🥺😭💔
Jay siyaram ❤️🪷
Jay bajrangbali
there is only one dsa course and one and only rohit negi bhaiya
Day 120/180 ✅
Slow and fast pointer chamak gya
bhaiya chamka diya vo bhi first attempt mein hi (Maza agya)
void removeLoop(Node* head) {
// code here
// just remove the loop without losing any nodes
Node * prev = NULL, * curr = head;
unordered_map visited;
while(curr){
if(visited[curr]==1)
break;
visited[curr]=1;
prev = curr;
curr = curr->next;
}
if(curr == NULL || curr->next== NULL)
return;
prev->next =NULL;
}
bhiaya ho gaya question 😀 but extra space leni padi muze unordered_map use kiya maine
//Function to remove a loop in the linked list.
void removeLoop(Node* head)
{
bool loop= false;
Node* slow=head, *fast=head;
while(fast!=NULL && fast->next!=NULL){
slow=slow->next;
fast=fast->next->next;
if(slow==fast ){
loop=true;
break;
}
}
if(loop){
Node* get;
unordered_maptrack;
while(1){
if(++track[head]==2){
get= head;
break;
}
head=head->next;
}
while(fast->next!=get) fast=fast->next;
fast->next=NULL;
}
}
remove loop
class Solution
{
public:
//Function to remove a loop in the linked list.
void removeLoop(Node* head)
{
// code here
if(head->next==head)
head->next=NULL;
Node* prev=NULL;
Node* current=head;
unordered_mapvisited;
while(current)
{
if(visited[current]==1)
{
prev->next=NULL;
return ;
}
prev=current;
visited[current]=1;
current=current->next;
}
// just remove the loop without losing any nodes
}
};
ak hi baar me ho gya :
😊
Bhaiya mern stack ka course kab Tak aaega
Good morning bhaiya ❤
Jai shree ram bhaiya
1:07:37 Homework
Node *removeLoop(Node *head)
{
Node *temp=head;
if(head==NULL){
return head;
}
if(head->next==NULL){
return head;
}
unordered_setset;
while(temp!=NULL){
if(set.find(temp->next)!=set.end()){
temp->next=NULL;
break;
}
set.insert(temp);
temp=temp->next;
}
return head;
}
chamak gya 11:05
121/180 done ✅✅✅✅
10:53Chamak gya
Day 121/180 👍👍
bhaiya es se bhi jyada bezzeti karo
Bhaiya unordered map mei aur question karao, Please taaki aache se chamak jaye
Bro Map pe dedicated video banega, don't worry
@coderArmy bhaiya ye to O(N) space me bhi accept ho gaya tha to fir aapko kese pata chala ki O(1) space complexity vala bhi solution exist karta hoga uske upar research karni chahie? ? kyunki soluiton accept hone ke baad to mud ke kon hi que ko dekhta hai vapas
bhai leetcode me mentioned rhta h time cmplxty of most optimised one
Bhai if we don't care about data then it is also working in ##detecting a loop
Node *temp=head;
int c=0;
while(temp){
temp->data=-1;
temp=temp->next;
if(temp){
if(temp->data==-1){
c=1;
break;
}
}
}
if(c==1)
return 1;
else
return 0;
in real world we only care for the data first and then time , but good technique BTW
Sir mujhay aik question poochna hay wo ye kay
Jab ham ne time complexity of detecting loop in lonked list nikali hay tab you said k
1+2+3+...n krein gay tou we will have order of n²
How n²
I thinking i am lacking in one of concepts
Can u please clear my question
bro learn arithmetic progression sum
dekho nested loop hai kyuki curr pointer null tk ja rha hai mtb O(N) and uske ander check fn bhi size of vector tk ja rha hai mtb null tk O(N) dono O(N^2) jb loop linear hoti hai tb add krte hai O(N)+O(N)=O(N) and nested mai O(N) * O(N)=O(N^2)
Bhaiya Radhe Radhe 🙏
chamak gya bhiayta
bhaiya agar LEETCODE pe question avaliable rehta he to LEETCODE pe solve karaya karo nahi to aapki marzi aap IIT se ho
bejati kriye bhiya 🤣🤣🤣
remove loop in linked list
class Solution {
public:
// Function to remove a loop in the linked list.
void removeLoop(Node* head) {
Node *slow = head, *fast = head;
while (fast != NULL && fast->next != NULL) {
slow = slow->next;
fast = fast->next->next;
// Detect if there's a loop
if (slow == fast) {
// Loop detected
if (fast == head) {
// If the loop starts from the head node itself
while (fast->next != head)
fast = fast->next;
fast->next = NULL;
} else {
// If the loop starts from some middle node
slow = head;
while (slow->next != fast->next) {
slow = slow->next;
fast = fast->next;
}
fast->next = NULL;
}
return; // Loop removed successfully
}
}
}
};
Bhaiya, abhi main 1st year me hun. Kya mujhe gate ki tayari karni chahiye ya programming and DSA me command banani chahiye?
just find clients who can pay you on and start working on projects , this way you can earn and learn
H/W=
2:20
Bhaiya coderarmy pe content show hi nhi ho rha..mtlb abb aage kya padhna hai uska detail nhi show ho rha hai..
Bhayia Video kaafi informative h, but apki video ki audio kano me chubhti h(sometimes suddenly too louds) so please fix..
Last home work solution:-
class Solution
{
public:
//Function to remove a loop in the linked list.
void removeLoop(Node* head)
{
// code here
// just remove the loop without losing any nodes
if(head==NULL ||head->next==NULL){
return;
}
Node *fast=head;
Node *slow=head;
while(fast!=NULL &&fast->next!=NULL){
fast=fast->next->next;
slow=slow->next;
if(slow==fast){
slow=head;
while(slow!=fast){
slow=slow->next;
fast=fast->next;
}
while(fast->next!=slow){
fast=fast->next;
}
fast->next=NULL;
return;
}
}
}
};
Bhaiya achhe se chamak raha ha .
by the way he is " lappu sa sachin 🤣🤣🤣"
# Bhaiya beijjati karo
mere code me TLE ni aa rha h
🙌
chamak chamk cham chamka re
🎉🎉🎉🎉