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.

Be the first one to answer
Add answer anonymously...
LTIMindtree Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

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

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter