C++/Java/Python/JavaScript ||🚀 ✅ With Explanation ||🚀 ✅ Linked List
Intuition:\nThe problem is to remove the nth node from the end of a linked list. We can find the total number of nodes in the linked list and then traverse the 
# Intuition:\nThe problem is to remove the nth node from the end of a linked list. We can find the total number of nodes in the linked list and then traverse the list again to find the nth node from the end. We can then remove the node by updating the pointer of the previous node.\n\n# Approach:\n\n1. Initialize a pointer to the head of the linked list and a count variable to 0.\n2. Traverse the linked list and increment the count for each node until the end of the list is reached.\n3. If the count is equal to n, remove the head node and return the next node as the new head.\n4. Otherwise, initialize the pointer to the head of the linked list again and set n to count - n - 1.\n5. Traverse the linked list again and update the pointer of the previous node to remove the nth node from the end.\n6. Return the head of the linked list.\n\n# Complexity:\n\n- Time Complexity: O(n), where n is the total number of nodes in the linked list. We need to traverse the linked list twice - once to count the total number of nodes and then to find the nth node from the end.\n\n- Space Complexity: O(1), as we are not using any extra space and only using constant space for the pointers and count variable.\n\n---\n# C++\n```\nclass Solution {\npublic:\n    ListNode* removeNthFromEnd(ListNode* head, int n) {\n        if(head==NULL){\n            return head;\n        }\n        ListNode* ptr=head;\n        int count = 0;\n        while(ptr){\n            count++;\n            ptr=ptr->next;\n        }\n        if(count==n){\n            head=head->next;\n            return head;\n        }\n        ptr=head;\n        n=count-n-1;\n        count=0;\n        while(ptr){\n            if(count==n){\n                ptr->next=ptr->next->next;\n            }\n            count++;\n            ptr=ptr->next;\n        }\n        return head;\n    }\n};\n```\n\n---\n# JAVA\n```\nclass Solution {\n    public ListNode removeNthFromEnd(ListNode head, int n) {\n        if (head == null) {\n            return head;\n        }\n        \n        ListNode ptr = head;\n        int count = 0;\n        while (ptr != null) {\n            count++;\n            ptr = ptr.next;\n        }\n        \n        if (count == n) {\n            head = head.next;\n            return head;\n        }\n        \n        ptr = head;\n        n = count - n - 1;\n        count = 0;\n        while (ptr != null) {\n            if (count == n) {\n                ptr.next = ptr.next.next;\n            }\n            count++;\n            ptr = ptr.next;\n        }\n        \n        return head;\n    }\n}\n\n```\n---\n# Python\n```\nclass Solution(object):\n    def removeNthFromEnd(self, head, n):\n        if head is None:\n            return head\n        \n        ptr = head\n        count = 0\n        while ptr is not None:\n            count += 1\n            ptr = ptr.next\n        \n        if count == n:\n            head = head.next\n            return head\n        \n        ptr = head\n        n = count - n - 1\n        count = 0\n        while ptr is not None:\n            if count == n:\n                ptr.next = ptr.next.next\n            count += 1\n            ptr = ptr.next\n        \n        return head\n\n```\n---\n\n# JavaScript\n```\nvar removeNthFromEnd = function(head, n) {\n        if (head === null) {\n            return head;\n        }\n        \n        let ptr = head;\n        let count = 0;\n        while (ptr !== null) {\n            count++;\n            ptr = ptr.next;\n        }\n        \n        if (count === n) {\n            head = head.next;\n            return head;\n        }\n        \n        ptr = head;\n        n = count - n - 1;\n        count = 0;\n        while (ptr !== null) {\n            if (count === n) {\n                ptr.next = ptr.next.next;\n            }\n            count++;\n            ptr = ptr.next;\n        }\n        \n        return head;\n};\n```
['Linked List', 'Python', 'C++', 'Java', 'JavaScript']