Find Nth Node from End
Easyjavapythonccppjavascript
Given a linked list and an integer K, find the K-th node from the end of the list (1-indexed).
Input Format
The first line contains two integers N and K. The second line contains N space-separated integers.
Output Format
Print the value of the K-th node from the end.
Example 1
Input
5 2 10 20 30 40 50
Output
40
Explanation: From the end, 50 is first and 40 is second.
- 1 <= K <= N <= 100000
- -1000000000 <= value <= 1000000000
Submit an attempt to unlock the solution. (Sign in first.)
Related Problems
- Create and Traverse a Linked ListEasy · java, python, c, cpp, javascriptSolve Problem
- Insert at Beginning of Linked ListEasy · java, python, c, cpp, javascriptSolve Problem
- Insert at End of Linked ListEasy · java, python, c, cpp, javascriptSolve Problem