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 and data ≠ -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!
Select
Add answer anonymously...
Greendeck Full Stack Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits