here is the question link of one of the similar problem reverse k node. i am not able to solve it. when last nodes left are less than k then what to do??
here is my code
Reverse k nodes
@aditikandhway hey just do k=k%length of linked list in starting and rest write same logic , you will get it correct as above will handle all cases. Dry run it with example after doing modulo you will get it.
when k is 3 the output should be 3 2 1 4 5 for input 1 2 3 4 5 but i am getting 3 2 1 5 4 which is wrong. although i followed what you said please check once https://ide.codingblocks.com/s/325441
@aditikandhwayhey your logic of updating pointers is wrong please check it again as k will be 3 if 3%5 is done so it will not affect your code, your logic of k reverse have problem.
can you tell me another way to solve this problem??
@aditikandhway hey check this code and dry run on 2 egs with k>length and k<length of ll you will get it: