in the above question i am submitting the solution as below and error is coming
Practicising ll
What problem do you face here?
Your code which I can see for k reverse linked list is fine. You can also take a reference from the below given code.
Node *reverse (Node *head, int k)
{
Node* current = head;
Node* next = NULL;
Node* prev = NULL;
int count = 0;
/*reverse first k nodes of the linked list */
while (current != NULL && count < k)
{
next = current->next;
current->next = prev;
prev = current;
current = next;
count++;
}
/* next is now a pointer to (k+1)th node
Recursively call for the list starting from current.
And make rest of the list as next of first node */
if (next != NULL)
head->next = reverse(next, k);
/* prev is new head of the input list */
return prev;
}
wrong output is coming
Make sure that your code for input and creating a linked list works fine. I am looking over for your main logic part. Also you can have a look at the previous code which I sent you is for the main logic part of k reversal
it is the question of online chalenge. can you please read the question properly
Can you share the link of the question