only two test cases are passing
Linked list k append
Do one simple thing -
Make a function which pushes the last node of the linked list to its front. Call it k times. And finally display the linked list obtained.
i think that would give tle as in that approach as for every last node to be inserted in front it will traverse till the end an what is wrong with my code please tell me that
i dry run my code it is working fine
No it will not give TLE. And it is the correct approach. Your code might give some errors as k can be any value - less than, equal to or greater than n. So there are chances that your code will miss out on some cases.
I suggest you to try and code the approach which I have explained to you.
sir in the hint video of this challenge riya mam has used the same approach but she has used the pointers differently
and as you mentioned that k can be greater then n then what we have to do in that case please explain with example
Lets say our linked list is - 1 2 3 4 and k = 5
So the correct output should be - 4 1 2 3
This is done as follows -
For k=1, the linked list returned is - 4 1 2 3
For k=2, the linked list returned is - 3 4 1 2
For k=3, the linked list returned is - 2 3 4 1
For k=4, the linked list returned is - 1 2 3 4
For k=5, the linked list returned is - 4 1 2 3
So just try to make a function which pushes the last node of the linked list to its front. Call it k times. And finally display the linked list obtained.