Leetcode 61. Rotate List | Linked Lists | Rotate linked list by k places to right

Поделиться
HTML-код
  • Опубликовано: 28 янв 2025

Комментарии • 44

  • @probabilitycodingisfunis1
    @probabilitycodingisfunis1  2 года назад +8

    //reach the last element??
    //last element -> head // 7->1

    if(head==NULL || k==0)return head;
    ListNode* temp = head;
    int n = 0;
    while(temp->next)
    {
    temp = temp->next;
    n++; // 6
    }
    //temp = 7
    temp->next = head; // 7->1

    //n = 6
    k = k%(n+1);
    int jump = n-k; // 6-2 = 4
    temp = head;
    while(jump)
    {
    temp = temp->next;
    jump--;
    }
    //temp -> 5
    ListNode* returnhead = temp->next; // 6
    temp->next = NULL;
    return returnhead;

    • @divyagupta6854
      @divyagupta6854 2 года назад

      There is one change which can be done to reduce cognitive complexity of the code. While calculating list length, instead of checking temp->next != null, we can do temp != null. In that case, n will hold exact length of linked list, and not one less than actual length. So, we won't have to do K = K%(n+1). Instead, K = K%n will be enough. Correct me if I am wrong.

  • @s4chin_verma
    @s4chin_verma Год назад +2

    Literally I had been stuck in this problem for last two hours but i don't give up and found your video. Thaks for kind of help

  • @divyagupta6854
    @divyagupta6854 2 года назад +7

    This was the only solution which was easy to understand, and without using any extra space in memory too. Thanks for the video.

  • @HarshSingh-hk8fe
    @HarshSingh-hk8fe Год назад +1

    the way you explain is just amazing thanks a lot

  • @aniruddhkarekar2818
    @aniruddhkarekar2818 Год назад +1

    Very easy solution ! Thankyou so much didi ! I saw That k %= n + 1; part in array rotate question as well but now I got it why it is used. Thanks again 😊

  • @lifeisgood9725
    @lifeisgood9725 Год назад +1

    Outstanding explanation. Thank You so much.

  • @mahaz-e-urdu8197
    @mahaz-e-urdu8197 Год назад

    Bht jaldi se samjha diya good work didi

  • @mlLearning490
    @mlLearning490 Год назад +1

    Amazing Explaination Ever !!!

  • @kidoo1567
    @kidoo1567 Год назад

    Fast like an express train🎉🎉 thank you😊 short and crisp..

  • @education03-l1n
    @education03-l1n Год назад +1

    def rotate(self, head, k):
    temp = head
    while(temp.next):
    temp = temp.next
    temp.next = head
    while k > 0:
    temp = temp.next
    k -=1

    head = temp.next
    temp.next = None
    return head

  • @UEEANILKUMAR
    @UEEANILKUMAR 2 года назад +1

    Thank you for explaning , wonderful explanation ✨✨✨

  • @rahulkoundal8289
    @rahulkoundal8289 2 года назад

    You explain so simple and easy way

  • @kumaravinashsinghabnish4021
    @kumaravinashsinghabnish4021 Год назад

    Gajab ka samjaya h 🎉⭐

  • @sharadkumar6658
    @sharadkumar6658 2 года назад

    Nice solution. It was good😇💫

  • @ROHANMANNA-il7nt
    @ROHANMANNA-il7nt 7 месяцев назад

    THANKS FOR THE SOLUTION🙂

  • @meandpenguinvlogs8221
    @meandpenguinvlogs8221 2 года назад +2

    Please daily upload 💞

  • @anglepriya05
    @anglepriya05 Год назад

    Nice explanation. But same logic will not work for left rotation. Could you explain that one also?

  • @yajatdhawan1865
    @yajatdhawan1865 2 года назад

    nice explanation from where did you improve your problem solving skills

    • @GhostRider....
      @GhostRider.... 2 года назад

      by coding on leetcode

    • @GhostRider....
      @GhostRider.... 2 года назад

      @@yajatdhawan1865 aisa reply krega to zindagi me nahi hoga tere se coding

    • @GhostRider....
      @GhostRider.... 2 года назад

      @@yajatdhawan1865 ok bhai

    • @yajatdhawan1865
      @yajatdhawan1865 2 года назад

      @@GhostRider.... accha tume batana hai na ye batao ki online assessment kese clear karu

    • @GhostRider....
      @GhostRider.... 2 года назад +1

      @@yajatdhawan1865 ek striver youtuber h, unne DSA ki sheet bana rakhi h usse solve kar ke complete kar do fir tum assessment clear par paoge, us sheet me maximum questions covered h jo product based companies me puche jate h

  • @sayansen0361
    @sayansen0361 Год назад

    Thanku so muchhhh

  • @dhananjoydey1337
    @dhananjoydey1337 2 года назад +1

    please please please keep uploading videos like this

  • @Musicallyright
    @Musicallyright 2 года назад

    Thanks. It was helpful

  • @mathematicssolution9482
    @mathematicssolution9482 Год назад

    Masha Allah Great job

  • @gunjanmatani3736
    @gunjanmatani3736 2 года назад

    nice explnation thank you so much can you explain the problem 396 leetcode problem please.

  • @preyashdwivedi7338
    @preyashdwivedi7338 Год назад

    Osmmm... explanation

  • @gowrisankar98jammu49
    @gowrisankar98jammu49 2 года назад

    nice explanation and please upload cloned linkelist videos i searched in ur videos i cant find it

  • @LeaveIT-yc9pq
    @LeaveIT-yc9pq 6 месяцев назад

    thank you didi

  • @vermadeen9181
    @vermadeen9181 2 года назад

    thank you so much

  • @abhishekkumarpandey6280
    @abhishekkumarpandey6280 2 года назад

    Thank u❣

  • @Arundevvb1
    @Arundevvb1 2 года назад

    Thank you

  • @rishisahu193
    @rishisahu193 2 года назад

    Best 💯

  • @sachinparmar8406
    @sachinparmar8406 2 года назад

    perfect

  • @rajan2757
    @rajan2757 2 года назад

    submit ho gaya didi ji

  • @darshankalathiya8667
    @darshankalathiya8667 2 года назад

    you are amazing teacher.. Please daily upload video will can help you subscribe your channel : )

  • @meghapaul1496
    @meghapaul1496 6 месяцев назад

    Gg

  • @thesoulofsugar1634
    @thesoulofsugar1634 11 месяцев назад

    HEADS OFF

  • @devakinandan23
    @devakinandan23 Год назад

    Thank you so much