hey i m getting 3 wrong answers on submission
please check:
3 wrong answers
Hi Aparna,
in your code code you haven’t considered the case (k>n).
So, just add an if statement i.e if(k>n){k=k%n;) in ur code.
Let take an example.
Suppose the given linked list is 1 2 3 4 5 and k=6, so it means 6th element from the end needs to be made as the new head. So, inorder to get the 6th element, we first traverse the linked list till we reach front(and do k-- along) and if k is still not 0, we again start traversing from the end. So , in this case 6th element from the end is 5 so the new linked list will look like 5 1 2 3 4. So, in order to get kth element if k>n, we can just add the condition if(k>n){k=k%n;) in the int main() section.
Hope that resolves ur doubt.
1 Like
Yes it works now thankyou