Not able to clear all test cases

#include
using namespace std;

class Node
{
public:
int data;
Node *next;

Node(int data)
{
    this->data = data;
    next = NULL;
}

};
void insertAtTail(Node *&head, int data, Node *&tail)
{
if (head == NULL)
{
head = new Node(data);
tail = head;
return;
}

Node *n = new Node(data);

tail->next = n;
tail = n;

}
void print(Node *head)
{
while (head != NULL)
{
cout << head->data << " ";
head = head->next;
}
}

Node *kAppend(Node head,int k)
{
if(head==NULL or head->next==NULL)
return head;
Node
slow=head, *fast=head;

while(k!=0)
{
    fast=fast->next;
    k--;
}
if(fast==NULL)
return head;

while(fast->next!=NULL)
{
    fast=fast->next;
    slow=slow->next;
}

Node* temp=slow;
slow=slow->next;
temp->next=NULL;

fast->next=head;
return slow;

}

int main()
{
int data;
int n;

cin >> n;
Node *head = NULL;
Node *tail = NULL;
while (n !=0)
{
    cin >> data;
    insertAtTail(head, data, tail);
    n--;
}

int k;
cin>>k;

// print(head);
// cout << endl;

// head = reverse(head);

head=kAppend(head,k);
print(head);

return 0;

}

hi @anandsingh3210
k =k%n u will have to include this as k can be very large compared to n…
Refer this code->

i am not able to understand your solution

explain your approach

image
just add this line k = k%n in ur code… it will pass all test cases…
ur corrected code–>

but i still don’t understand this, how k could be larger than n, isn’t wrong input

According to constraints it can be larger than k… hence it was the trick in the ques…

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.