How will write the while condition?

Not able to figure out how would I do that.

hello @udatta

what u are asking? condition of while loop will depend on ur logic.

kth from end means n-kth from start so u can run loop while (i<n-k) and move the head pointer that many time to next node and then print
or use any other approach in that casee while condition will be different