Question bank › Linked List
Dsa Linked List Warm-up

Find the K-th Element from the End

Given a linked list, find the k-th element from the end of the list. You must print the value of that element. If k is larger than the length of the list, output 'Index out of range'. Input format: - The first line contains an integer n (0 <= n <= 100), the number of nodes. - The second line contains n space-separated integers representing the values of the linked list. - The third line contains an integer k (1 <= k <= n). Output format: - The value of the k-th element from the end, or 'Index out of range' if applicable. Example: Input: 5 10 20 30 40 50 2 Output: 40

Key concepts

linked_listkth_elementtraversal

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
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.