Challenge: Return the Nth Node from the End

Returning the Nth node from the start of a linked list is easy. Can you return the Nth node from the end of a list?

Problem Statement

In the findNth function, a certain N is specified as an argument. You simply need to return the node itself (not the value of the node), which is N spaces away from the end of the linked list.

Input

A linked list and a position n.

Output

The value of the node n positions from the end. Returns null if n is out of bound.

Sample Input

LinkedList = 22->18->60->78->47->39->99 and n = 3

Sample Output

47

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