...

/

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

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:

g head head a 1 head->a NULL NULL b 1 a->b c 2 b->c d 3 c->d e 4 d->e f 5 e->f f->NULL

Sample input

...
Access this course and 1400+ top-rated courses and projects.