Delete at a Given Position in a Linked List

You are given the head of a singly linked list (as an array of node values from head → tail) and a 0-indexed position k. Remove the node sitting at position k…

You are given the head of a singly linked list (as an array of node values from **head → tail**) and a 0-indexed position `k`. Remove the node sitting at position `k` and return the head of the resulting list. Position is counted from the head starting at 0: deleting position 0 removes the head and the second node becomes the new head. If `k` is out of range — that is, `k` is less than 0 or greater than or equal to the number of nodes — return the list unchanged. The relative order of the surviving nodes is preserved. **Indexing convention:** this platform uses 0-based indexing throughout all data structures — position 0 refers to the head node. For example, with `head = [10, 20, 30, 40]` and `k = 2`, the result is `[10, 20, 40]`.

- `1 <= nodes.length <= 10^5` - `-10^9 <= nodes[i] <= 10^9` - `k` is an integer; positions are 0-indexed (the head is position 0). - If `k < 0` or `k >= nodes.length` the list is returned unchanged (no-op).

Example 1: input head = [10,20,30,40], k = 2; output [10, 20, 40]. Position 2 holds 30. Walk to position 1 (value 20) and point its next at the node after 30, so 30 is bypassed.

Example 2: input head = [7,14,21], k = 0; output [14, 21]. Position 0 is the head. Move the head pointer to the second node; the old head 7 is dropped.

Example 3: input head = [99], k = 0; output []. A single-node list at position 0 — the head becomes null and the list is now empty.

Category: Linked List. Topic: linked-list. Difficulty: Easy. Patterns: linked-list-traversal.