Remove the Kth Node from the End of a Linked List
You are given a singly Linked List with 'N' nodes containing integer data and an integer 'K'. Your task is to delete the Kth node from the end of this Linked List.
Input:
The first line of input contains an integer 'T', the number of test cases or queries. For each test case: - The first line contains an integer 'K', indicating the position (1-based) from the end of the list to be removed. - The second line lists the elements of the singly linked list, separated by spaces, ending with -1. The value -1 is a terminator and not a part of the list.
Output:
For each test case, output a single line containing the updated linked list with elements separated by a single space, concluding the list with -1. Print each test case on a separate line.
Example:
Input: 1 - 2 3 4 -1
Output: 1 2 4 -1
Constraints:
- 1 <= 'T' <= 5
- 0 <= 'N' <= 105
- 0 <= 'K' <= 'N'
- 1 <= 'DATA' <= 109 and 'DATA' != -1
- Time Limit: 1 sec.
Note:
You only need to implement the function. Do not print anything as it will be handled for you.

AnswerBot
4mo
Remove the Kth node from the end of a singly linked list.
Traverse the linked list to find the length 'N'.
Calculate the position to delete from the beginning as 'N - K + 1'.
Delete the node at the calcu...read more
Help your peers!
Add answer anonymously...
Amdocs Senior Java Developer interview questions & answers
A Senior Java Developer was asked Q. What is association?
A Senior Java Developer was asked Q. Which list implementation would you use for frequent insertions and deletions, a...read more
A Senior Java Developer was asked Q. Write a program to merge two lists.
Popular interview questions of Senior Java Developer
A Senior Java Developer was asked Q1. What is association?
A Senior Java Developer was asked Q2. Which list implementation would you use for frequent insertions and deletions, a...read more
A Senior Java Developer was asked Q3. Write a program to merge two lists.
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

