Rotate List | Rotate a Linked List | Leetcode | Complete Full Tree Data Structure | Hello World
Vložit
- čas přidán 28. 10. 2021
- This is the video under the series of DATA STRUCTURE & ALGORITHM in a TREE Playlist. We are going to understand How to Rotate the Linked List or complete rotateRight functions
Join My Telegram channel for more Updates: telegram.me/helloworldbyprince
complete DSA preparation: github.com/Prince-1501/Comple...
----------------------------------------------------------------------------------------
► 61. Rotate List
Given the head of a linked list, rotate the list to the right by k places.
Input: head = [1,2,3,4,5], k = 2
Output: [4,5,1,2,3]
We also Provide courses on Competitive Programming and Data structure and Algorithms. Please see our Full Playlist on our Channel.
----------------------------------------------------------------------------------------:
Rotate List: leetcode.com/problems/rotate-...
code in This Video: github.com/Prince-1501/Hello_...
----------------------------------------------------------------------------------------
*Follow me *
LinkedIn► / iamprince
Facebook► / helloworldofficials
Instagram► / helloworldbyprince
Twitter► / prince_king_
Telegram► telegram.me/helloworldbyprince
----------------------------------------------------------------------------------------
►Our Playlists on:-
► Tree: • Tree Data Structure & ...
► Hashing: • Hashing Data Structure...
► Matrix: • Matrix (Multidimension...
► STL: • Standard Template Libr...
► Leetcode: • LeetCode Solutions And...
►Competitive Programming: • Full course in Competi...
►C++ Full Course : • C++ full Course in HINDI
►Algorithms: • L-01 || Prefix Sum Arr...
►Data Structure: • Data Structures with C...
------------------------------------------------------------------------
🌟 Please leave a LIKE ❤️ and SUBSCRIBE for more AMAZING content! 🌟
✨ Tags ✨
Rotate Linked List
Rotate List
Linked List-Playlist in Hindi
Use of Linked List Data structure in real Life
question asked in Google
question asked in Amazon
off-campus placement
how to learn to code for beginners
Practice Tree data structure
LinkedList in data structure
The linked list data structure in Hindi
linked List Full playlist for Beginners
#linkedList #Leetcode #programming
Sir I used to always fear from LinkedList from my First year of Btech, Now in 4th year I found your playlist and got my doubts cleared.
Thanks yaar ❤️ please share and support my channel
I got the logic part of the problem ,but missed the specials cases like when n == k , n == 0 or n == 1 .Great explaination and I love the way you encourage students to solve the questions on thier own .
this was indeed the best explanation for this question on internet
I made it a circular linked list by pointing last node to head and then rotated it by k positions to make a new head. Afterwards, I updated the previous node of the new head to point to null, effectively breaking the circular structure. This operation allows the linked list to be correctly rotated to the right by k positions.
bhaii but tle maar raha hn
Naya concept sikhne ko mila thanks ❤
I am on my way to complete this linked list series and im feeling very good and bad at the same time good beacause this series built my confidence a lot i never even approached ll before but now i can solve them and bad because im about to finish this series😭😭..i need more such videos bhaiya
thanks a lot for supporting yaar Please, share this channel in your college, groups, or LinkedIn bcoz it's cost nothing to you 😀
you explained very nicely. .......masum.
Sir, you are good explain this question.
attempt kiya or ho v gya thanks bhaiya attempt to karna chahiye . but I am still watching your solution.🙂
Thank you bhai.
Your Explaination is very well. 🙂🙂🙂👍👍👍
Thanks Nadeem
you explained very nicely. Thank you!!
Thanks
Bass share kar do yaar dosto ke sath 😀
@@HelloWorldbyprince sure sir!!
Thanks bhaiya for making videos your explanation is really good.
Thanks and welcome
Nice explanation ✨
Thanks a lot
Please share my channel with your friends or in college groups 😊
Great 🙌🙌
Thanks a lot
16:06 FUNNY MOMENT OF THE VIDEO HI PRINCE
😂😂
@@HelloWorldbyprince THANK YOU FOR REPLAY WHAT IS YOUR CTC
Tanks bhaiya
keep learning bro
apne bola tough h mt sochna lkin yeh toh apki vedio dekhne ke bad aisa ho hi ni skta koi prblm tough lge phle lg rha tha lkin ab nhi
Hahaha good work buddy, keep it up
Bhaiya thanku aapki first line video ko pause karo or khud try karo . Mai pahle karta tha 10 min fir direct jump lakin aapli line se mai ek baar or jata hu back mai 15 min or lagata hu fir nahu hota tab aapke pass aaata hu solu dekhnge or understanding bad jaati hai question ko leke
haa bhai same mere sath bhi hua aur literally un 15-20 minute me hum ya to solve kr pare hai question ya fir ekdm karib hote hai ans ke
class Solution {
public ListNode rotateRight(ListNode head, int k) {
int n=0;
ListNode temp=head,curr=head,tempp=head;
while(temp!=null){
n++;
temp=temp.next;
}
if(head==null){
return head;
}
int rotate=k%n;
int loop=n-rotate;
if(n==1||n==loop){
return head;
}
int j=0;
while(tempp!=null){
j++;
if(j==loop){
curr=tempp.next;
tempp.next=null;
break;
}else{
tempp=tempp.next;
}
}
tempp=curr;
while(tempp.next!=null){
tempp=tempp.next;
}
tempp.next=head;
return curr;
}
}
amazing work brother keep learning like this
nice
Thanks
but this code not accepted by gfg
bhaiya eska time complexity kya hai??....GFG me time limit exceeded show kar rha
Time complexity bole to ....
Aapka code utne time run nahi ho raha kitne me hona chahiye
Mera ek video hai
TLE by hello world ...dekh lo
czcams.com/video/mBpvsmtCG9k/video.html
Bhaiya Geeks for Geeks me same question hai per run nahi ho rha
@@Sangamkumar017 gfg par left shift hai and this problem is a right shift hai.
ListNode*slow=head,*fast=head;
if(head==NULL||head->next==NULL||k==0) return head;
while(k--){
fast=fast->next;
}
while(fast!=NULL&&fast->next!=NULL){
slow=slow->next;
fast=fast->next;
}
ListNode*temp_head=slow->next;
slow->next=NULL;
fast->next=head;
return temp_head;
bhaiya hum aise v to solve kr skte hai ......slow and fast pointers se
if(head==NULL){
return head;
}else if(head->next==NULL){
return head;
}
int count = 0;
ListNode *temp = head;
while(temp!=NULL){
count++;
temp = temp->next;
}temp = head;
if(countnext;
}
ListNode *head_n = temp->next;
temp->next =NULL;
res = head_n;
ListNode *temp_res =res;
while(temp_res->next!=NULL){
temp_res = temp_res->next;
}
temp_res->next = head;
return res;
good work ravil, keep learning
your code is wrong sir