bhaiya , iski approach mai help karna thodi.
LL-k reverse . . . .
Hey @CODER_JATIN The need of the question is to reverse every k nodes (where k is an input to the function) and k is a factor of size of List.
Reverse the first sub-list of size k.
1.1 While reversing keep track of the next node and previous node.
1.2 Let the pointer to the next node be next and pointer to the previous node be prev.
head->next = reverse(next, k)
/* Recursively call for rest of the list and link the two sub-lists */
return prev
Now prev becomes the new head of the list (see the iterative method)
N = 9 & K = 3
Original LL is : [9 -> 4 -> 1] -> [7 -> 8 -> 3] -> [2 -> 6 -> 5]
After k Reverse : [1 -> 4 -> 9] ->[ 3 -> 8 -> 7] ->[ 5 -> 6 -> 2]
Now you just have to reverse them.
bhaiya 3no list alag alag to reverse ho gyi , lekin fir unko merge kese karey?
Isko recursively socho. Jaise maan lo ki hume first 3 elements ko reverse krdiya , uske baad humne recursion ko bola ki jao, bachi hui linked list ko bhi 3 ke group mai reverse krke aao.
This is our recursive call .
Take this into consideration
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.
