L reverse list problem

I m trying to do this this :

  1. firstly try to store the curnode as the kth elements and a temp for the cur->next for second sublist.

  2. how to get the previous node for the first sublist like
    we have 9->5->1
    i have write a loop to make the current as the 1 know i am not able to understand how to make 1->5 . Or do we have to do the same things like done in reverse a list video where the first element points to null after reversing.

  • Reverse the first sub-list of size k. While reversing keep track of the next node and previous node. Let the pointer to the next node be next and pointer to the previous node be prev . (https://www.geeksforgeeks.org/reverse-a-linked-list/) for reversing a linked list.
  • head->next = reverse(next, k) ( Recursively call for rest of the list and link the two sub-lists )
  • Return prev ( prev becomes the new head of the list

@chhavibansal got ur point help me to understand the TLE i already ping u in the other thread

1 Like

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.