Kth Last Node of a Linked List
Given a singly linked list node, return the value of the kth last node (0-indexed). k is guaranteed not to be larger than the size of the linked list.
This should be done in \(\mathcal{O}(1)\) space.
Constraints
- n ≤ 100,000where- nis the length of- node
https://binarysearch.com/problems/Kth-Last-Node-of-a-Linked-List
Examples
Example 1
Input
- node =
- k = 1
Output
- answer = 1
Explanation
The second last node has the val of 1
Example 2
Input
- node =
- k = 2
Output
- answer = 1
 
       
      
Leave a comment