Challenge: Return the Nth Node from End

Let’s try returning the Nth node from the start of a linked list.

Problem Statement: #

In the find_nth function, a certain N is specified as an argument. You simply need to return the node which is N spaces away from the None 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 -1 if n is out of bounds.

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.