One Passed Linked-List Node Value

Write a function that returns the value of the linked-list node when given the linked-list and the count from the right.

Linked-list:

Example Cases

Possible Solutions

Using 2 Passes

Idea: In first pass, count total of linked-list nodes. Subtract the second argument from the total (position). In the second pass, go to the node that equals position and return list.value.

Using 1 Pass

Idea: Track the count and make another value equal to the second argument (position). Traverse through the linked-list using list.next() and through each iteration update list.next() to list.next().next().