Dsa
Linked List
Easy
Find the Kth Element from the End of a Linked List
You are given a linked list and an integer k. Write a program to find the kth element from the end of the linked list.
Input format:
- The first line contains an integer n, the number of elements in the linked list.
- The next n lines contain integers for the linked list.
- The last line contains the integer k, the position from the end.
Output format:
- Print the value of the kth element from the end.
Example:
Input:
5
10
20
30
40
50
2
Output:
40
Key concepts
linked_listindexingtraversal
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now