L22. Rotate a LinkedList

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

Komentáře • 112

  • @sagarchakrabarty7838
    @sagarchakrabarty7838 Před 7 měsíci +41

    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😊.

  • @rushidesai2836
    @rushidesai2836 Před 3 měsíci +3

    You have made my basics so clear that I was able to come up with a solution without your explanation!

  • @hat_awesome21
    @hat_awesome21 Před 7 měsíci +10

    U r literally helping lots of students , thanks a lot

  • @hat_awesome21
    @hat_awesome21 Před 7 měsíci +33

    bhaiya plz upload stack and queue , placements are coming

  • @manjunathadharagond9322
    @manjunathadharagond9322 Před 7 měsíci +13

    God of DSA TUTORIALS🔥

  • @varunpalsingh3822
    @varunpalsingh3822 Před 7 měsíci +2

    Thank you striver, understood ❤

  • @amankira2333
    @amankira2333 Před 5 měsíci

    Bro hattsoff!! now i am feeling confident in linked list topic.
    thanks

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

    I have done this problem thank you Striver ❤

  • @gauravbairagi209
    @gauravbairagi209 Před 7 měsíci +2

    great video

  • @harshitgarg2820
    @harshitgarg2820 Před 7 měsíci +4

    Completed all the given videos and their corresponding questions. I'm eagerly waiting for the remaining videos🚀🚀

  • @nithishkumarsaravanan969
    @nithishkumarsaravanan969 Před 4 měsíci +2

    Look at his eyes! says his dedication

  • @nileshk19
    @nileshk19 Před 7 měsíci

    Thank You Striver❣.
    Understood.

  • @kingstock5654
    @kingstock5654 Před 7 měsíci +12

    Striver ig these are few remaining probs
    • Clone a Linked List with random and next pointer
    • flattening of LL
    • sort a LL

    • @takeUforward
      @takeUforward  Před 7 měsíci +11

      Yes will upload in 3/4 days.

    • @ganjinaveen7338
      @ganjinaveen7338 Před 7 měsíci +4

      @@takeUforward
      please upload remaining videos striver sir

    • @keerthanpailwan6477
      @keerthanpailwan6477 Před 7 měsíci +3

      striver please upload next videos@@takeUforward

    • @TheSpiritualOne401
      @TheSpiritualOne401 Před 7 měsíci +1

      please upload sir
      @@takeUforward

    • @takeUforward
      @takeUforward  Před 7 měsíci +3

      Yes I will, thoda sa I am an road, will do it. @@TheSpiritualOne401

  • @lucifersamrat6280
    @lucifersamrat6280 Před 12 dny

    god level explanation bhai

  • @zyzzbrah9429
    @zyzzbrah9429 Před 7 měsíci +4

    bro stacks,queues,bits,strings upload karo bhai please

  • @PivotGamer
    @PivotGamer Před 7 měsíci +2

    Im learning from you, Strings playlist when 😁

  • @Irritate-lu1bt
    @Irritate-lu1bt Před 6 měsíci

    one more subscriber ..hats off

  • @naamhaii
    @naamhaii Před 7 měsíci +11

    Stack and queue playlist please

    • @Akhillbj
      @Akhillbj Před 7 měsíci +2

      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

    • @naamhaii
      @naamhaii Před 7 měsíci

      @@Akhillbj ☪️🔫

    • @bruvhellnah
      @bruvhellnah Před 7 měsíci

      @@Akhillbj Ignore these clowns lol. They go on demanding on every video without ever putting any efforts of their own lol

    • @Akhillbj
      @Akhillbj Před 7 měsíci

      @@bruvhellnah some one has to start somewhere, chill karo bhai

    • @mbm.editzz
      @mbm.editzz Před 7 měsíci

      @@bruvhellnah atleast he's requesting politely totally uncalled for to call him a clown

  • @user-go9vs3vm5d
    @user-go9vs3vm5d Před 2 měsíci

    solved on my own
    credit goes to you
    really helpful .....

  • @codeguy21
    @codeguy21 Před 7 měsíci +4

    bhai next stack and queue plz

  • @Hemanthkumar-ck1zu
    @Hemanthkumar-ck1zu Před 7 měsíci +1

    The dsa a2z sheet and the 79 sheet is not accessible
    Can you please look into this
    Thankyou.

  • @nileshbahetwar2816
    @nileshbahetwar2816 Před 7 měsíci +2

    Sir sde sheet who knows DSA is working fine but why a2z sde sheet showing "file not found error"?
    Are you updating the sheet?

  • @dayashankarlakhotia4943
    @dayashankarlakhotia4943 Před 7 měsíci +2

    Your code TLE in gfg?

  • @user-gk4zy6bk7l
    @user-gk4zy6bk7l Před 7 měsíci +5

    Bhaiya string aur bit manipulation bhi la do🥺🥺

  • @dorothybhowmicktopic6889
    @dorothybhowmicktopic6889 Před 4 měsíci +1

    Amazingggggg🎉

  • @sakshijain8549
    @sakshijain8549 Před 7 měsíci +2

    Bhaiya!! DSA AtoZ playlist is not working, I follow only your playlist to study, your playlist was so helpful.Please make it available again...

  • @jk-sj4nf
    @jk-sj4nf Před 7 měsíci +13

    hey striver , can we expect stack & queue as next plz

  • @user-hl1go9pb9u
    @user-hl1go9pb9u Před 7 měsíci +1

    striver i practicing in this A2Z sheet but its not loading from yesterday kindly someone please inform what to do

  • @AmanSharma-xy1qm
    @AmanSharma-xy1qm Před 7 měsíci +3

    Bhaiya website ke articles unreachable bta rhe hai, kb tk back hogi website??

  • @keshabkrishnadas4674
    @keshabkrishnadas4674 Před 6 měsíci +1

    Done and Dusted ✅✅😎

  • @YourCodeVerse
    @YourCodeVerse Před 5 měsíci

    Understood✅🔥🔥

  • @namannema3349
    @namannema3349 Před 7 měsíci +1

    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

  • @user-tk2vg5jt3l
    @user-tk2vg5jt3l Před 4 měsíci

    Thank you Bhaiya

  • @bishalkundu7592
    @bishalkundu7592 Před 7 měsíci

    Understood ❤

  • @Saloni-gr1gq
    @Saloni-gr1gq Před 7 měsíci

    Why the course sheet is not opening please do something

  • @himanshuyadav0600
    @himanshuyadav0600 Před 7 měsíci +3

    Next Stack , Queue, Strings playlist sir please..

  • @vigneshmohankumar3388
    @vigneshmohankumar3388 Před 7 měsíci +1

    What happened to the website, we r getting 503 service unreachable error. Please resolve it.

  • @aplakusattakharyab
    @aplakusattakharyab Před 7 měsíci +2

    guys website is down

  • @NARUTOUZUMAKI-bk4nx
    @NARUTOUZUMAKI-bk4nx Před 5 měsíci

    Understooood

  • @hardikpatel352
    @hardikpatel352 Před 2 měsíci +1

    understood

  • @ak27129
    @ak27129 Před 7 měsíci

    is this series completed now?

  • @jritzeku
    @jritzeku Před 3 měsíci

    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.

  • @Oldmonk3321
    @Oldmonk3321 Před 2 měsíci

    Yes bhai please upload stack abd queues 😢

  • @rajvardhan465
    @rajvardhan465 Před 7 měsíci

    Sorry aak like this this is in java dsa or python or
    Both concepts are same please explain sir

  • @GagandeepSingh-cp1pe
    @GagandeepSingh-cp1pe Před 7 měsíci +1

    complete the playlist soon ✨

  • @manjunathadharagond9322
    @manjunathadharagond9322 Před 7 měsíci +3

    Striver community ❤

  • @dewanandkumar8589
    @dewanandkumar8589 Před 2 měsíci

    Understood

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

    understood!

  • @corporateAniruddha
    @corporateAniruddha Před 7 měsíci

    Vaiya baki videos kab tak ayenga

  • @saikumargatla4706
    @saikumargatla4706 Před 7 měsíci +3

    Next series on recursion.Like if if you want next series on recursion

  • @anshror2583
    @anshror2583 Před 6 měsíci +1

    Bhai next playlist greedy please

  • @nikunjkhakhkhar1030
    @nikunjkhakhkhar1030 Před 5 měsíci +1

    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 😊

  • @user-go9vs3vm5d
    @user-go9vs3vm5d Před 2 měsíci

    i am already practising dsa from many days but
    starting day1 of my dsa for tracking

  • @helloworld2054
    @helloworld2054 Před 7 měsíci +3

    Your eyes 😧

  • @State_exam_preparation
    @State_exam_preparation Před 7 měsíci +1

    QUESTION!
    Is it possible to get element before kth node if head is pointing to kth node??singly ll

    • @kushagrasahay
      @kushagrasahay Před 7 měsíci

      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

    • @State_exam_preparation
      @State_exam_preparation Před 7 měsíci

      @@kushagrasahay you can't traverse,that's the catch only.

    • @kushagrasahay
      @kushagrasahay Před 7 měsíci

      @@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.

    • @kushagrasahay
      @kushagrasahay Před 7 měsíci

      that is possible in case of doubly LL

    • @kushagrasahay
      @kushagrasahay Před 7 měsíci

      @@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

  • @MJBZG
    @MJBZG Před 6 dny

    could write it on my own

  • @noobyerror7815
    @noobyerror7815 Před měsícem

    just adding a extension (correct me if i am wrong) roate the linked list in ANTI-CLOCKWISE direction.
    .
    .
    .
    ,
    .
    ..
    .
    .
    .
    .
    .
    .

  • @ganeshvhatkar9253
    @ganeshvhatkar9253 Před 5 měsíci

    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;

  • @kushagrasharma2738
    @kushagrasharma2738 Před 6 měsíci +3

    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.

  • @gauravbairagi209
    @gauravbairagi209 Před 7 měsíci +2

    1st comment

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

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

  • @printfiamd5254
    @printfiamd5254 Před 7 měsíci +2

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

  • @buvaneswari8461
    @buvaneswari8461 Před 5 měsíci

    Yeah done and dusted

  • @sayalihere-sm3yx
    @sayalihere-sm3yx Před 6 měsíci

    please complete string and rest ,as u get time 😅

  • @user-gk4zy6bk7l
    @user-gk4zy6bk7l Před 2 měsíci

    god

  • @johnyjangid8541
    @johnyjangid8541 Před 7 měsíci +2

    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😢😢

    • @vaibhavvm4147
      @vaibhavvm4147 Před 7 měsíci +1

      same q

    • @johnyjangid8541
      @johnyjangid8541 Před 7 měsíci +1

      @@vaibhavvm4147 Please reply anybody

    • @AdityaGarg-hl7ri
      @AdityaGarg-hl7ri Před 7 měsíci +1

      Bro code kro and keep the codes with comments with you

    • @johnyjangid8541
      @johnyjangid8541 Před 7 měsíci +1

      @@AdityaGarg-hl7ri Bro to matlab notes
      Cause I am an absolute Newbie
      Who doesn't know anything about DSA

    • @AdityaGarg-hl7ri
      @AdityaGarg-hl7ri Před 7 měsíci +1

      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

  • @likhithalikhitha-rs1ry
    @likhithalikhitha-rs1ry Před 7 měsíci +2

    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

  • @jyothiyadav2595
    @jyothiyadav2595 Před 2 měsíci

    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??

  • @japleencrafts4690
    @japleencrafts4690 Před 7 měsíci +1

    Ghatiya video... Bhaisaab ki awaaz itni acchiii h ki mujhe need nhi a pa rhiiii bhyiiiii... Bs krooooooo😢😢😢

  • @zyzzbrah9429
    @zyzzbrah9429 Před 7 měsíci +3

    bro stacks,queues,bits,strings upload karo bhai please

  • @harshitpatil6138
    @harshitpatil6138 Před 5 měsíci

    understood

  • @himanshidafouty347
    @himanshidafouty347 Před měsícem

    Understood

  • @zyzzbrah9429
    @zyzzbrah9429 Před 7 měsíci +3

    bro stacks,queues,bits,strings upload karo bhai please

  • @zyzzbrah9429
    @zyzzbrah9429 Před 7 měsíci +3

    bro stacks,queues,bits,strings upload karo bhai please

  • @zyzzbrah9429
    @zyzzbrah9429 Před 7 měsíci +3

    bro stacks,queues,bits,strings upload karo bhai please

  • @aasimahsan6167
    @aasimahsan6167 Před 7 měsíci

    understood