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

Sdílet
Vložit
  • čas přidán 10. 03. 2022
  • Connect with me on LinkedIn : / alisha-parveen-80579850
    Check out our other playlists:
    Dynamic Programming:
    • Dynamic Programming
    Trees:
    • Trees
    Heaps and Maps:
    • Heaps and Maps
    Arrays and Maths:
    • Arrays and Maths
    Bit Manipulation:
    • Bit Manipulation
    Greedy Algorithms:
    • Greedy Algorithms
    Sorting and Searching:
    • Sorting and Searching
    Strings:
    • Strings
    Linked Lists:
    • Linked Lists
    Stack and Queues:
    • Stacks and Queues
    Two Pointers:
    • Two pointers
    Graphs, BFS, DFS:
    • Graphs, DFS, BFS
    Backtracking:
    • Backtracking
    Non- DSA playlists:
    Probability:
    • Probability
    SQL-Basic Join functions:
    • SQL - Basic JOIN Funct...
    SQL-Basic Aggregate functions:
    • SQL-Basic Aggregate Fu...

Komentáře • 42

  • @probabilitycodingisfunis1

    //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 Před 2 lety

      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.

  • @divyagupta6854
    @divyagupta6854 Před 2 lety +6

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

  • @s4chin_verma
    @s4chin_verma Před 9 měsíci +1

    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

  • @ROHANMANNA-il7nt
    @ROHANMANNA-il7nt Před měsícem

    THANKS FOR THE SOLUTION🙂

  • @HarshSingh-hk8fe
    @HarshSingh-hk8fe Před 6 měsíci

    the way you explain is just amazing thanks a lot

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

    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 😊

  • @mlLearning490
    @mlLearning490 Před rokem +1

    Amazing Explaination Ever !!!

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

    Osmmm... explanation

  • @rahulkoundal8289
    @rahulkoundal8289 Před 2 lety

    You explain so simple and easy way

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

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

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

    Outstanding explanation. Thank You so much.

  • @UEEANILKUMAR
    @UEEANILKUMAR Před 2 lety

    Thank you for explaning , wonderful explanation ✨✨✨

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

    Please daily upload 💞

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

    please please please keep uploading videos like this

  • @sayansen0361
    @sayansen0361 Před rokem

    Thanku so muchhhh

  • @mahaz-e-urdu8197
    @mahaz-e-urdu8197 Před 7 měsíci

    Bht jaldi se samjha diya good work didi

  • @vermadeen9181
    @vermadeen9181 Před 2 lety

    thank you so much

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

    Thank you so much

  • @user-kf8gq7ks9b
    @user-kf8gq7ks9b Před 11 měsíci +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

  • @Musicallyright
    @Musicallyright Před rokem

    Thanks. It was helpful

  • @abhishekkumarpandey6280

    Thank u❣

  • @mathematicssolution9482

    Masha Allah Great job

  • @sharadkumar6658
    @sharadkumar6658 Před rokem

    Nice solution. It was good😇💫

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

    Gajab ka samjaya h 🎉⭐

  • @Arundevvb1
    @Arundevvb1 Před rokem

    Thank you

  • @sachinparmar8406
    @sachinparmar8406 Před rokem

    perfect

  • @rishisahu193
    @rishisahu193 Před rokem

    Best 💯

  • @gunjanmatani3736
    @gunjanmatani3736 Před rokem

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

  • @anglepriya05
    @anglepriya05 Před rokem

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

  • @gowrisankar98jammu49
    @gowrisankar98jammu49 Před rokem

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

  • @rajan2757
    @rajan2757 Před rokem

    submit ho gaya didi ji

  • @darshankalathiya8667
    @darshankalathiya8667 Před 2 lety

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

  • @yajatdhawan1865
    @yajatdhawan1865 Před rokem

    nice explanation from where did you improve your problem solving skills

    • @GhostRider....
      @GhostRider.... Před rokem

      by coding on leetcode

    • @GhostRider....
      @GhostRider.... Před rokem

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

    • @GhostRider....
      @GhostRider.... Před rokem

      @@yajatdhawan1865 ok bhai

    • @yajatdhawan1865
      @yajatdhawan1865 Před rokem

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

    • @GhostRider....
      @GhostRider.... Před rokem +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

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

    HEADS OFF