Ll -k reverse link list problem

https://hack.codingblocks.com/contests/c/471/116
https://ide.codingblocks.com/s/62902

my code is not working , can u plz check the code.

Hi Ayush, please check your reverselist() function. It is messing up your list too badly. Also there are some more error in your code. Testcases below may help you:

//Input 0
15 5
9 4 1 7 8 3 2 6 5 4 7 3 2 5 4
//Output 0
8 7 1 4 9 4 5 6 2 3 4 5 2 3 7

//Input 1
16 4
9 4 1 7 8 3 2 6 5 8 4 7 3 2 5 4
//Output 1
7 1 4 9 6 2 3 8 7 4 8 5 4 5 2 3

Your code kind of seems to always reverse 3 elements
Pls correct your logic and code now :slight_smile:

1 Like