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