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 given the position 'K'.
Traverse the list to find the length 'N' of the linked list.
Calculate the position from the beginning as 'N - K + 1'.
Del...read more
Help your peers!
Add answer anonymously...
Oracle Application Developer interview questions & answers
An Application Developer was asked 9mo agoQ. Given the heads of two singly linked-lists headA and headB, return the node at w...read more
An Application Developer was asked 10mo agoQ. How do you calculate area using coordinates?
An Application Developer was asked 10mo agoQ. Given a set of points in the xy-plane, find the minimum area of a square that co...read more
Popular interview questions of Application Developer
An Application Developer was asked 10mo agoQ1. How do you calculate area using coordinates?
An Application Developer was asked 10mo agoQ2. Given a set of points in the xy-plane, find the minimum area of a square that co...read more
An Application Developer was asked 11mo agoQ3. Given an array of integers, find the maximum length of a subarray with a given s...read more
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

