What is wrong with my code?
Hi @tusharnitharwal , the algo you are using is not correct
for eg : lets take eg of
5 2
1 2 3 4 5
In the first iteration
start=1;
temp=2;
after for loop
use=3
1->next=4
free=3
use=1
after for loop
use=5
use->next =2 // ll is 1->4->5->2->3
and here when u do temp->next=start
i.e. 2->next=1;
then u have lost 3 and made a loop in your ll i.e 1->4->5->2->1->4…
thus u can see that start will never be NULL so u will be stuck inside loop will never end
I will highly suggest you to use recursion for these type of problem I will provide you with algo and pseudo code
Algorithm :
Reverse the first sub-list of size k.
1.1 While reversing keep track of the next node and previous node.
1.2 Let the pointer to the next node be next and pointer to the previous node be prev.
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 (see the diagrams of iterative method of this post) */
Function Code
Node reverse(Node head, int k)
{
Node current = head;
Node next = null;
Node prev = null;
int count = 0;
/* Reverse first k nodes of linked list */
while (count < k && current != null)
{
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 now head of input list
return prev;
}
In case of any doubt feel free to ask 
If you got the answer mark you doubt as resolved
hit a like if you liked the answer 