L22. Rotate a LinkedList
Vložit
- čas přidán 28. 11. 2023
- Problem Link: tinyurl.com/ye23ua58
Entire LL Sheet: takeuforward.org/linked-list/...
Check our A2Z DSA Course: takeuforward.org/strivers-a2z...
Please do give us a like, and subscribe to us if you are new to our channel.
Do follow us on our socials: linktr.ee/takeuforward
Hi Striver Bhakta!!! I want to convey my heartfelt gratitude for the transformative impact your course has had on my life. Hailing from a village in Assam, where aspirations often go unnoticed, your story and structured content became my guiding light. Today, standing at Deloitte, I owe this achievement to your inspiration and the invaluable A to Z DSA sheet. Thank you for changing lives and paving the way for countless individuals like me. Being a BSc CS grad, I never imagined entering the IT field. I am eagerly looking forward to completing your SDE sheet, anticipating further growth and learning. May your journey be filled with unparalleled success😊.
How much LPA have you got?
@@priyaaofficial7 16
You have made my basics so clear that I was able to come up with a solution without your explanation!
U r literally helping lots of students , thanks a lot
bhaiya plz upload stack and queue , placements are coming
Ur semester pls?
i would urge bhaiya to complete all the pending topics asap
God of DSA TUTORIALS🔥
Thank you striver, understood ❤
Bro hattsoff!! now i am feeling confident in linked list topic.
thanks
I have done this problem thank you Striver ❤
great video
Completed all the given videos and their corresponding questions. I'm eagerly waiting for the remaining videos🚀🚀
how many are remaining?
@@Movies-7914 three
Look at his eyes! says his dedication
Thank You Striver❣.
Understood.
Striver ig these are few remaining probs
• Clone a Linked List with random and next pointer
• flattening of LL
• sort a LL
Yes will upload in 3/4 days.
@@takeUforward
please upload remaining videos striver sir
striver please upload next videos@@takeUforward
please upload sir
@@takeUforward
Yes I will, thoda sa I am an road, will do it. @@TheSpiritualOne401
god level explanation bhai
bro stacks,queues,bits,strings upload karo bhai please
Im learning from you, Strings playlist when 😁
one more subscriber ..hats off
Stack and queue playlist please
Ruk ja, bhai woh bhi toh insaan hi hai!
Till then why not read more about those things and understand them how much ever you can
@@Akhillbj ☪️🔫
@@Akhillbj Ignore these clowns lol. They go on demanding on every video without ever putting any efforts of their own lol
@@bruvhellnah some one has to start somewhere, chill karo bhai
@@bruvhellnah atleast he's requesting politely totally uncalled for to call him a clown
solved on my own
credit goes to you
really helpful .....
bhai next stack and queue plz
The dsa a2z sheet and the 79 sheet is not accessible
Can you please look into this
Thankyou.
Sir sde sheet who knows DSA is working fine but why a2z sde sheet showing "file not found error"?
Are you updating the sheet?
Your code TLE in gfg?
Bhaiya string aur bit manipulation bhi la do🥺🥺
Amazingggggg🎉
Bhaiya!! DSA AtoZ playlist is not working, I follow only your playlist to study, your playlist was so helpful.Please make it available again...
hey striver , can we expect stack & queue as next plz
striver i practicing in this A2Z sheet but its not loading from yesterday kindly someone please inform what to do
Bhaiya website ke articles unreachable bta rhe hai, kb tk back hogi website??
Done and Dusted ✅✅😎
Understood✅🔥🔥
hey i dont have intrest in reading the article to see the solution but striver bhaiya has told first to see article and then video i love to understand from video only what should i do @take U forward
Thank you Bhaiya
Understood ❤
Why the course sheet is not opening please do something
Next Stack , Queue, Strings playlist sir please..
What happened to the website, we r getting 503 service unreachable error. Please resolve it.
guys website is down
Understooood
understood
is this series completed now?
Is there link to this code solution plus diagrams? I recall seeing them in descriptions during your Trees playlist but not finding in LinkList section.
Yes bhai please upload stack abd queues 😢
Sorry aak like this this is in java dsa or python or
Both concepts are same please explain sir
complete the playlist soon ✨
Striver community ❤
Understood
understood!
Vaiya baki videos kab tak ayenga
Next series on recursion.Like if if you want next series on recursion
Bhai next playlist greedy please
Can we use the same logic as you shown in previous video, remove kth node from end of linked list, from that video we can use the part where we maintain distance between fast and slow, then in single pass only we will be able to do this, and no need to compute length.
By the way you are doing great work 😊
i am already practising dsa from many days but
starting day1 of my dsa for tracking
Your eyes 😧
QUESTION!
Is it possible to get element before kth node if head is pointing to kth node??singly ll
you can take a dummy node and while traversing LL with head assign head to dummy. In this way when you reach kth node you will have a dummy pointing to (k-1)th
@@kushagrasahay you can't traverse,that's the catch only.
@@State_exam_preparation there is no way to stay on a node and reach its previous and linked lists are complelety based on linear traversals.
that is possible in case of doubly LL
@@State_exam_preparation moreover, we are not having any extra traversals. The traversal in which you go till kth node. In that only you get the previous one. Just taking an extra pointer
could write it on my own
just adding a extension (correct me if i am wrong) roate the linked list in ANTI-CLOCKWISE direction.
.
.
.
,
.
..
.
.
.
.
.
.
Understood Sir, i had done by dummy node concept then after I deleted it.
Node *rotate(Node *head, int k) {
Node* temp=head;
int len=0;
Node* prevnode=NULL;
Node* tail=NULL;
while(temp!=NULL){
len++;
if(temp->next==NULL){
tail=temp;
}
temp=temp->next;
}
temp=head;
if(k>len) k=k%len;
int reach=len-k;
if(reach==len || reach==0){
return head;
}
while(reach!=0){
reach--;
prevnode=temp;
temp=temp->next;
}
Node* dummynode=new Node(-1);
Node* current=dummynode;
current->next=temp;
tail->next=head;
prevnode->next=NULL;
Node* newhead= dummynode->next;
free(dummynode);
return newhead;
Why are you not uploading your course videos with consistency sir😅?? We wanna make this AtoZ sheet course best DSA course ever.. but it needs videos consistency.. when all video solution of your sheet questions will be available.. it becomes a best best best DSA course 🔥. Please bhaiya complete this 😊❤️.. i hope with new year you upload strings..stack..queue..bits questions solutions.
1st comment
Finally did que myself,
//function to find Lenth of LL : 0(N)
int lenOfList(ListNode* head){
ListNode* temp = head;
int cnt = 0;
while(temp != nullptr){
cnt++;
temp = temp->next;
}
return cnt;
}
//function to rotate
ListNode* rotateRight(ListNode* head, int k) {
//corner case , if head is null do nothing and if only one element how many times u may rotate itself is head,
if(head == nullptr || head->next == nullptr) return head;
//Finding Length
int len = lenOfList( head);
//if k>N bounding k
k = k % len;
//slow and fast pointers
ListNode* fast = head;
ListNode* slow = head;
//moving fast ptr till k so that next traverse slow will at one step behind rotation pt and fast at last node
for( int i = 1 ; inext;
}
//now fast node is at last and slow is rotation pt
while(fast!= nullptr && fast->next != nullptr){ //O(1/2N) total 2N and no space used;
slow = slow->next;
fast = fast->next;
}
//if fast not null then only its next is head , for linking i did this
if(fast!= nullptr)fast->next = head;
//new head for rotated list
head = slow->next;
slow->next = nullptr;//unlink
return head;
}
What about this approach???
int lengthOfLL(Node *head)
{
int cnt = 0;
while (head != NULL)
{
++cnt;
head = head->next;
}
return cnt;
}
Node *rotateKTimes(Node *head, int k)
{
if (head == NULL || head->next == NULL)
return head;
int l = lengthOfLL(head);
for (int i = 0; i < k % l; i++)
{
Node *temp = head;
while (temp->next->next != NULL)
{
temp = temp->next;
}
Node *newNode = temp->next;
temp->next = NULL;
newNode->next = head;
head = newNode;
}
return head;
}
Yeah done and dusted
please complete string and rest ,as u get time 😅
god
Ok someone please reply
How to watch Stirver's DSA Tutorials like:- Array, Now how to watch it I mean
Do i have to write the code in my copy,
Or code along with Striver
Please someone tell me the best way😢😢
same q
@@vaibhavvm4147 Please reply anybody
Bro code kro and keep the codes with comments with you
@@AdityaGarg-hl7ri Bro to matlab notes
Cause I am an absolute Newbie
Who doesn't know anything about DSA
i will suggest watch each video twice , first try to understand and code in vs code or any problem solving site then watch it again and make notes by your own understanding of the concept
take u forward website is not working and is showing file not found everywhere it would become very hard for us without that sheet please look into this i cant find any help line so i commented hope it would be visible and action will be taken...I'll be very thankful if it gets checked and i love the content and course provided by you
def rotateRight(self, head, k):
"""
:type head: ListNode
:type k: int
:rtype: ListNode
"""
def reversell(node):
if node.next:
return node
newnode=reversell(node.next)
front=node.next
front.next=node
node.next=None
return newnode
temp,count=head,0
while temp:
count+=1
temp=temp.next
k=k%count
index=count-k
slow=head
for i in range(1,index):
slow=slow.next
nextnode=slow.next
print(nextnode.val)
if nextnode==None:
return head
slow.next=None
firstpart=reversell(head)
print("first")
lastpart=reversell(nextnode)
print("next")
head.next=lastpart
head=reversell(firstpart)
print("last")
return head
can someone tell me why is
this not working??
Ghatiya video... Bhaisaab ki awaaz itni acchiii h ki mujhe need nhi a pa rhiiii bhyiiiii... Bs krooooooo😢😢😢
bro stacks,queues,bits,strings upload karo bhai please
understood
Understood
bro stacks,queues,bits,strings upload karo bhai please
bro stacks,queues,bits,strings upload karo bhai please
bro stacks,queues,bits,strings upload karo bhai please
understood