Recusive approach

can you please explain recursive approach to this problem

You can first build your linked list and then You can use the recursive approach for reversing the list… The only thing to keep in mind is that you need to maintain a counter so as to count the no of variables and reverse the list upto that point only…

node* kReverse(node head, int k)
{
node
curr_head = head;
nodecurr_next = NULL;
node
curr_prev = NULL;

int counter = 0;

while(curr_head != NULL && counter < k)
{
    curr_next = curr_head->next;
    curr_head->next = curr_prev;
    curr_prev = curr_head;
    curr_head = curr_next;
    counter++;
}

if(curr_next != NULL)
{
    head->next = kReverse(curr_next, k);
}

return curr_prev;

}