Given a linked list, return the element n positions from the last node in the list. Assume that endIndex
will always
be less than the length of the list.
Challenge | Solution |
Do not use a counter variable, do not retrieve the size
of the list, and only iterate through the *whole- list one
time.
val l = LinkedList<Char>()
l.insertLast('a')
l.insertLast('b')
l.insertLast('c')
l.insertLast('d')
l.insertLast('e')
fromLast(l, 0)?.data shouldBeEqualTo 'e'
fromLast(l, 3)?.data shouldBeEqualTo 'b'