Rotate List | Rotate a Linked List | Leetcode | Complete Full Tree Data Structure | Hello World

Sdílet
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

Komentáře • 45

  • @minalmahala5260
    @minalmahala5260 Před rokem +2

    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.

  • @ultron1060
    @ultron1060 Před rokem +1

    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 .

  • @srishtigaur6907
    @srishtigaur6907 Před 11 měsíci

    this was indeed the best explanation for this question on internet

  • @vishalalpe5903
    @vishalalpe5903 Před 11 měsíci +1

    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.

  • @satendrachauhan5120
    @satendrachauhan5120 Před 6 měsíci

    Naya concept sikhne ko mila thanks ❤

  • @ajaybachate7137
    @ajaybachate7137 Před rokem +2

    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

    • @HelloWorldbyprince
      @HelloWorldbyprince  Před rokem +1

      thanks a lot for supporting yaar Please, share this channel in your college, groups, or LinkedIn bcoz it's cost nothing to you 😀

  • @masumali8356
    @masumali8356 Před rokem

    you explained very nicely. .......masum.

  • @sachinbharti3016
    @sachinbharti3016 Před 6 měsíci

    Sir, you are good explain this question.

  • @kholiyamails1257
    @kholiyamails1257 Před rokem

    attempt kiya or ho v gya thanks bhaiya attempt to karna chahiye . but I am still watching your solution.🙂

  • @nadeemmehraj5873
    @nadeemmehraj5873 Před rokem

    Thank you bhai.
    Your Explaination is very well. 🙂🙂🙂👍👍👍

  • @Sangamkumar017
    @Sangamkumar017 Před 2 lety +1

    you explained very nicely. Thank you!!

  • @vanitlokhande3760
    @vanitlokhande3760 Před rokem

    Thanks bhaiya for making videos your explanation is really good.

  • @sukritimaurya2600
    @sukritimaurya2600 Před rokem

    Nice explanation ✨

    • @HelloWorldbyprince
      @HelloWorldbyprince  Před 11 měsíci

      Thanks a lot
      Please share my channel with your friends or in college groups 😊

  • @anshumansharma1069
    @anshumansharma1069 Před 10 měsíci

    Great 🙌🙌

  • @rajankhunt7002
    @rajankhunt7002 Před 2 lety +2

    16:06 FUNNY MOMENT OF THE VIDEO HI PRINCE

  • @engineerzavlogs3511
    @engineerzavlogs3511 Před rokem +1

    Tanks bhaiya

  • @neerajnegi1958
    @neerajnegi1958 Před 9 měsíci

    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

  • @utkarshsinghalus3085
    @utkarshsinghalus3085 Před rokem

    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

    • @ajaybachate7137
      @ajaybachate7137 Před rokem

      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

  • @priyanshuthakur8947
    @priyanshuthakur8947 Před rokem +1

    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;
    }
    }

  • @anckoor
    @anckoor Před 2 lety

    nice

  • @mantujaiswal9773
    @mantujaiswal9773 Před 4 měsíci

    but this code not accepted by gfg

  • @Sangamkumar017
    @Sangamkumar017 Před 2 lety +1

    bhaiya eska time complexity kya hai??....GFG me time limit exceeded show kar rha

    • @HelloWorldbyprince
      @HelloWorldbyprince  Před 2 lety +2

      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

    • @Sangamkumar017
      @Sangamkumar017 Před 2 lety

      Bhaiya Geeks for Geeks me same question hai per run nahi ho rha

    • @jayeshnayee6735
      @jayeshnayee6735 Před 2 lety +1

      @@Sangamkumar017 gfg par left shift hai and this problem is a right shift hai.

  • @the_notex
    @the_notex Před rokem

    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

  • @ravilpatel7301
    @ravilpatel7301 Před rokem +1

    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;

  • @Aman-om2tj
    @Aman-om2tj Před 4 měsíci

    your code is wrong sir