1) make initial pass through linked list to get length
2) make second pass to remove any reference to nth to last node
Let’s draw out how this might work with an example
Given linked list 1->2->3, n = 1 (we want to return 1->2) First pass, we get length = 3. Since n = 1, that means we want to remove the 3 -1 = 2 node (with index starting at 0)
As we iterate through the list..
at node 1 -> numberOfNodesSeen = 0, previousNode = null
at node 2-> numberOfNodesSeen = 1, previousNode = 1
at node 3 -> numberOfNodesSeen = 2, previousNode = 2 -> we set previousNode.next = node.next (node 3’s next = null)