JAVA SOLUTION 100% FASTER, with explanation, also asked in interviews
Upvote if you found this use full\n\nAlso asked in Adobe, Amazon, Arcesium, Factset, Intuit, Zoho, HCL\n\n\n// Steps-\n    \n// Use a dummy variable pointing to
**Upvote if you found this use full**\n\n**Also asked in Adobe, Amazon, Arcesium, Factset, Intuit, Zoho, HCL**\n\n```\n// Steps-\n    \n// Use a dummy variable pointing to head\n\n// Use two pointer fast and slow pointing to dummy variable . Move first pointer for n steps\n\n// Then start moving both until first pointer reaches the last node and slow pointer reaches (size of list - n)th node.\n    \n// Then delete the next node of slow and return dummy.next;\n\n\n// Concept-\n    \n// When you move the fast pointer to nth node, the remaining nodes to traverse is (size_of_linked_list - n).     \n// After that, when you start moving slow pointer and fast pointer by 1 node each, \n// it is guaranteed that slow pointer will cover a distance of (size_of_linked_list - n) nodes. And that\'s node we want to remove.\n\n\nclass Solution \n{\n    public ListNode removeNthFromEnd(ListNode head, int n) \n    {\n        if(head.next==null)\n            return null;\n        ListNode dummy=new ListNode();\n        dummy.next=head;\n        ListNode slow=dummy;\n        ListNode fast=dummy;\n        \n        for(int i=1;i<=n;i++)\n            fast=fast.next;\n        \n        while(fast.next!=null)\n        {\n            fast=fast.next;\n            slow=slow.next;\n        }\n        \n        slow.next=slow.next.next;\n        return dummy.next;\n    }\n}\n\n```\n\n**Without using dummy node**\n\n```\nclass Solution \n{\n    public ListNode removeNthFromEnd(ListNode head, int n) \n    {\n        if(head.next==null)\n            return null;\n        \n        ListNode slow=head;\n        ListNode fast=head;\n        \n        for(int i=1;i<=n;i++)\n            fast=fast.next;\n        \n        // edge case handeled when we have to delete the 1st node i.e n=size of linked list\n        \n        if(fast==null)\n            return head.next;\n        \n        while(fast!=null && fast.next!=null)\n        {\n            fast=fast.next;\n            slow=slow.next;\n        }\n        \n        slow.next=slow.next.next;\n        return head;\n    }\n}\n\n```
['Java']