Easy Beginner Friendly 🔥|| Beats 100% || Notes++ || Java, C++, Python 
Intuition & ApproachComplexityCode
# Intuition & Approach
![1.jpg](https://assets.leetcode.com/users/images/f7cccb43-7bf0-4216-ab03-78371f216b68_1741844416.8658564.jpeg)


# Complexity
![image.png](https://assets.leetcode.com/users/images/c8ef4076-d99c-47c9-8ce8-5990df11e545_1741844375.2998748.png)

# Code
```java []
class Solution {
    public ListNode removeNthFromEnd(ListNode head, int n) {
        ListNode res = new ListNode(0, head);
        ListNode dummy = res;
        for(int i=0;i<n;i++) head = head.next;
        while(head!=null){
            head = head.next;
            dummy = dummy.next;
        }
        dummy.next = dummy.next.next;
        return res.next;
    }
}
```
```c++ []
class Solution {
public:
    ListNode* removeNthFromEnd(ListNode* head, int n) {
        // Create a dummy node to handle edge cases
        ListNode* res = new ListNode(0, head);
        ListNode* dummy = res;

        // Move the head pointer n steps forward
        for (int i = 0; i < n; i++) {
            head = head->next;
        }

        // Move both pointers until head reaches the end
        while (head != nullptr) {
            head = head->next;
            dummy = dummy->next;
        }

        // Remove the nth node from the end
        dummy->next = dummy->next->next;

        // Return the updated list
        return res->next;
    }
};
```
```python []
# Definition for singly-linked list.
class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next

class Solution:
    def removeNthFromEnd(self, head: ListNode, n: int) -> ListNode:
        # Create a dummy node to handle edge cases
        res = ListNode(0, head)
        dummy = res

        # Move the head pointer n steps forward
        for _ in range(n):
            head = head.next

        # Move both pointers until head reaches the end
        while head:
            head = head.next
            dummy = dummy.next

        # Remove the nth node from the end
        dummy.next = dummy.next.next

        # Return the updated list
        return res.next

```
![ok.png](https://lh6.googleusercontent.com/proxy/c1LeLv7686Z3O0EwMYz1lmGtbXDKOiBX-BuRnwKeGTNuZe0BvX8zRUkiGoFz8uYyPzx4HakbmPxP_Vtd0EUIAPOoej-NiUQub0ONve7eniMitSoN-mHyAeT499TCJF8KA1cTRUiEqyg4MoHYvmeuJGxj-ssy)
['Linked List', 'Two Pointers', 'Python', 'C++', 'Java']