Given a linked list, remove the nth node from the end of list and return its head.
Given linked list: 1->2->3->4->5->null, and n = 2.
After removing the second node from the end, the linked list becomes 1->2->3->5->null.
There are two approaches we can use to solve this problem:
Count length: we first count the length of the linked list, then on a second pass, we know which node to remove. This approach requires two passes.
Two pointers: this approach requires only one pass of the list. We use two node pointers, a and b, where a is n nodes ahead of b. We then advance both a and b at the same speed. When a reaches the end of the list, b is the node to be removed.