Find n'th Node from the End of a Linked List

Given a singly linked list, return the nth node from the last node. Return null if n is larger than the size of the list.

Statement

We’re given a singly linked list. Return the nthn^{th} node from the last node. Return null if n is larger than the size of the list.

Example

In the example below, the value of the third to the last node is 3:

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.