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.
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 😊
@@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
//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;
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.
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
This was the only solution which was easy to understand, and without using any extra space in memory too. Thanks for the video.
the way you explain is just amazing thanks a lot
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 😊
Outstanding explanation. Thank You so much.
Bht jaldi se samjha diya good work didi
Amazing Explaination Ever !!!
Fast like an express train🎉🎉 thank you😊 short and crisp..
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
Thank you for explaning , wonderful explanation ✨✨✨
You explain so simple and easy way
Gajab ka samjaya h 🎉⭐
Nice solution. It was good😇💫
THANKS FOR THE SOLUTION🙂
Please daily upload 💞
Nice explanation. But same logic will not work for left rotation. Could you explain that one also?
nice explanation from where did you improve your problem solving skills
by coding on leetcode
@@yajatdhawan1865 aisa reply krega to zindagi me nahi hoga tere se coding
@@yajatdhawan1865 ok bhai
@@GhostRider.... accha tume batana hai na ye batao ki online assessment kese clear karu
@@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
Thanku so muchhhh
please please please keep uploading videos like this
Thanks. It was helpful
Masha Allah Great job
nice explnation thank you so much can you explain the problem 396 leetcode problem please.
Osmmm... explanation
nice explanation and please upload cloned linkelist videos i searched in ur videos i cant find it
thank you didi
thank you so much
Thank u❣
Thank you
Best 💯
perfect
submit ho gaya didi ji
you are amazing teacher.. Please daily upload video will can help you subscribe your channel : )
Gg
HEADS OFF
Thank you so much