Change Start Node Problem Statement
You are provided with a singly linked list and an integer K
. The objective is to make the Kth
node from the end of the linked list the starting node of the linked list.
Input:
The first line contains the elements of the singly linked list, each separated by a single space and terminated with -1 (note: -1 is not part of the list).
The second line contains a single integer ‘K’.
Output:
Output the updated list elements separated by space.
Example:
Suppose the input linked list is 1 2 3 4 5 -1
and K = 2
. After updating, the output should be 4 5 1 2 3
.
Constraints:
1 <= N <= 5*105
1 <= K <= N
-109 <= data <= 109
anddata ≠ -1
Time Limit: 1 second
Note:
‘K’ will always be valid, ensuring the operation can be performed correctly. There is no need to print anything; it has already been managed. Just implement the logic to transform the linked list as required.

AnswerBot
4mo
Modify a singly linked list to make the Kth node from the end the starting node.
Traverse the linked list to find the length and the Kth node from the end
Update the pointers to make the Kth node the ne...read more
Help your peers!
Add answer anonymously...
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

