Linked list k-append problem

Given a linked list of length N and an integer K , append the last K elements of a linked list to the front. Note that K can be greater than N.

Input Format
First line contains a single integer N denoting the size of the linked list.
Second line contains N space separated integers denoting the elements of the linked list.
Third line contains a single integer K denoting the number of elements that are to be appended.

Constraints
1 <= N <= 10^4
1 <= K <= 10^4

Output Format
Display all the elements in the modified linked list.

Sample Input
7
1 2 2 1 8 5 6
3
Sample Output
8 5 6 1 2 2 1

my solution - https://ide.codingblocks.com/s/318611
it is giving run error please check

Hey @Abhishmu5
Your code is working fine for cases when k<=n-1 but its not handling the rest of the cases
Please look into this and you will get AC.

Hey, If your doubt is resolved then please mark it resolved :slight_smile:
Otherwise let me know the issue .