2 pointer, with original submission and thought process. Faster than 98%.
So this is the original code in my submission. I\'d apparently visited this a few months back and made a hash of it, but after revisiting having learnt some bas
So this is the original code in my submission. I\'d apparently visited this a few months back and made a hash of it, but after revisiting having learnt some base techniques it\'s much easier.\n\n**(1)** \nOk obviously need to delete a node. So best know how to do that. Already in my mind i\'m seeing:\n\n``` \nconst deleteNextNode = (node) => node.next = node.next.next\n```\n\nWhich means if we want to delete a node, we need to get the node before it.\n\n**(2)**\nThen the other bit, which actually comes before in the description, is to get the `Nth` node from the end. In our case, as we want to get the `Nth` node from the end of the linked list to delete it, we actually want to get the `Nth+1` node **from the end**. Seems like a slow/fast 2 pointer solution.\n\nTo do this, i\'m seeing the beginning of the answer to the entire question:\n\n```\nvar removeNthFromEnd = function(head, n) {\n\n    if(!head) return head\n\n    let [slow, fast] = [head, head]\n\t\n    // move fast ahead by n\n\t// have to be careful about --n or n-- here. \n\t// As we want the node before the one we are deleting,\n\t// we want fast to be ahead by an additional node\n\t// if the question was just to return slow, i\'d probably use --n instead\n    while(n--){\n        fast = fast.next\n    }\n    \n\t// we want to stop when fast.next is null\n\t// we move both along the linked list \n\t// keeping the same distance between them\n    while(fast.next){\n        [slow, fast] = [slow.next, fast.next]\n    }\n\t...\n}\n```\n\nOne final issue came up when submitting. What happens when `n` is equal to the length of the linked list. We\'ll we run into problems. Easiest solution I could think of is to create a dummy node that is before the linked list. That allows us to remove the head node if the Nth node from the end is the head node.\n\n**Final submission:**\n```\n/**\n * @param {ListNode} head\n * @param {number} n\n * @return {ListNode}\n */\nvar removeNthFromEnd = function(head, n) {\n    if(!head) return head\n    let begin = { val: -1, next: head }\n       \n    let [slow, fast] = [begin, begin]\n    // move fast ahead by n\n    while(n--){\n        fast = fast.next\n    }\n    \n    while(fast.next){\n        [slow, fast] = [slow.next, fast.next]\n    }\n    \n    // remove slow.next\n    removeNextNode(slow)\n    \n    return begin.next\n};\n\nconst removeNextNode = (node) => { \n    node.next = node.next.next\n}\n```
['Two Pointers', 'JavaScript']