DSA Tracker

Medium

Delete Node in Linked List

A medium Linked List problem included in Apna College, Love Babbar 450. Below: the roles whose interviews prioritise this topic, and how to practise it.

Topic
Linked List
Sheets
2
Core for
3 roles
Platform
LeetCode

The problem

Delete a node from a linked list when you are only given access to that node (not the head).

Example 1

Input
node=5 in [4,5,1,9]
Output
[4,1,9]

Example 2

Input
node=1 in [4,5,1,9]
Output
[4,5,9]

Example 3

Input
node=9 in [4,5,1,9]
Output
[4,5,1]

Constraints

  • The node to delete is not the tail
  • At least 2 nodes exist

How to think about it

Updated 2026-09-09

You cannot update the preceding node's next pointer because singly linked lists do not carry backward references. Instead of cutting out the current node container, disguise it: copy the value from the subsequent node into this one, then excise that subsequent node instead.

Approaches, worst first

  1. Shift every later value left

    time O(n) · space O(1)

    Walk forward from the given node copying each successor's value one step back, then unlink the final node once the tail is reached. It produces the right list and is the loop most people write before spotting the trick, but it touches the whole suffix to delete one node, and it still needs the second-to-last node to cut the tail loose.

  2. Value shift and successor bypassWrite this one

    time O(1) · space O(1)

    Copy `node.next.val` directly into `node.val`, then rewire `node.next = node.next.next`. The given node assumes the successor's identity and deletes the now-redundant duplicate, achieving node removal without needing access to any predecessor.

Where people lose marks · 3
  • Attempting this strategy on the tail node fails completely because `node.next` is null, leaving no subsequent value to copy or node to bypass.
  • Setting `node = null` merely clears the local variable reference without altering the linked list structure in heap memory.
  • Failing to bypass `node.next` leaves two consecutive nodes holding duplicate values rather than deleting any element.

The theory behind it

Linked List — the ground this problem stands on. All Linked List problems

What Linked List is

A linked list is a chain of separate cargo cars connected by coupling hooks, scattered anywhere across memory rather than sitting in a tidy contiguous row. Each car, called a node, holds a single piece of data and a pointer directing traffic to the address of the next car in line. Because nodes connect only by directional links, jumping straight to the tenth car is impossible without walking past the first nine.

When to reach for it

Choose a linked list when a problem requires frequent insertions and deletions at known positions without shifting whole blocks of surrounding memory. Problems mentioning pointer splicing, reversing subsequences in place, merging sorted streams, or detecting cycles in linear chains strongly point here. It is ideal when total capacity is unpredictable and memory allocation must happen one individual node at a time.

How the pattern works

Think in terms of pointer rewiring before dereferencing. Keep a dummy head node pointing to the start of the list so modifications to the initial item do not require separate edge logic. Always save references to neighboring nodes into temporary variables before cutting or redirecting forward links. When diagnosing loops or locating middle nodes, advance two references simultaneously at differing velocities so traversal completes without supplementary storage.

What each operation costs

OperationTime
insert or delete at the headO(1)
insert or delete after a known nodeO(1)
find an element by value or positionO(n)
What usually goes wrong with Linked List
  • Losing access to the remainder of the chain by overwriting a next reference before caching the downstream node address in a temporary variable.
  • Attempting to read properties of a null node reference after walking one step beyond the tail or advancing a fast runner without checking its next step.
  • Creating an accidental infinite cycle by pointing a trailing node back into earlier segments of the chain without severing old outgoing links.

Which roles need this problem

Linked List is a core topic for these 3 roles — if you're targeting one of them, this problem is early in your path, not optional.

Secondary for 5 more roles, including Full-Stack Developer, Android Developer, iOS Developer.

Track this in your role's order

Pick your target role and all 370 problems — including this one — resequence to what that interview actually asks. Free.

Start free

More Linked List problems

Problem set and role mapping as of .