PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates proficiency in singly linked list manipulation, specifically pointer handling and in-place node removal, and falls under the Coding & Algorithms domain.

  • medium
  • Capital One
  • Coding & Algorithms
  • Software Engineer

Remove nodes with a given value

Company: Capital One

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

## Problem You are given the head of a singly linked list and an integer `target`. Remove **all** nodes whose value equals `target`, and return the (possibly new) head of the list. ### Input - `head`: head node of a singly linked list (may be `null`) - `target`: integer ### Output - The head of the linked list after deletions ### Constraints - Number of nodes: `0 <= n <= 10^5` - Node values and `target` fit in 32-bit signed integer - Must run in `O(n)` time and `O(1)` extra space (not counting the list itself) ### Examples 1) `1 -> 2 -> 6 -> 3 -> 4 -> 5 -> 6`, `target = 6` ⇒ `1 -> 2 -> 3 -> 4 -> 5` 2) `7 -> 7 -> 7`, `target = 7` ⇒ *(empty list)* 3) *(empty list)*, `target = 1` ⇒ *(empty list)*

Quick Answer: This question evaluates proficiency in singly linked list manipulation, specifically pointer handling and in-place node removal, and falls under the Coding & Algorithms domain.

You are given the head of a singly linked list and an integer target. Remove all nodes whose value equals target, and return the possibly new head of the list. For this coding environment, the linked list is represented as a Python list of node values in order. An empty list [] represents a null head. Return the final linked list in the same format. Example: - head = [1, 2, 6, 3, 4, 5, 6], target = 6 - result = [1, 2, 3, 4, 5]

Constraints

  • 0 <= len(head) <= 10^5
  • Each node value and target fits in a 32-bit signed integer
  • The intended linked list algorithm should run in O(n) time
  • Use O(1) auxiliary space for the linked list pointer manipulation

Examples

Input: ([1, 2, 6, 3, 4, 5, 6], 6)

Expected Output: [1, 2, 3, 4, 5]

Explanation: Both nodes with value 6 are removed, including the one at the tail.

Input: ([7, 7, 7], 7)

Expected Output: []

Explanation: Every node matches the target, so the result is an empty list.

Input: ([], 1)

Expected Output: []

Explanation: The input list is already empty, so nothing changes.

Input: ([5], 5)

Expected Output: []

Explanation: The single node matches the target and is removed.

Input: ([-1, 2, -1, 3, -1], -1)

Expected Output: [2, 3]

Explanation: All occurrences of -1 are removed, leaving only 2 and 3.

Input: ([2147483647, -2147483648, 2147483647], 2147483647)

Expected Output: [-2147483648]

Explanation: Both maximum 32-bit integer values are removed, leaving the middle node.

Hints

  1. A dummy (sentinel) node before the head makes it easy to delete nodes at the front of the list.
  2. Instead of moving two pointers separately, try checking current.next so you can relink around nodes that should be removed.
Last updated: Apr 19, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Solve Four Coding Assessment Tasks - Capital One (medium)
  • Write SQL using joins and window functions - Capital One (medium)
  • Review Preprocessing Code and Tests - Capital One (easy)
  • Solve multiple algorithmic interview questions - Capital One (hard)
  • Place Pieces on a Grid - Capital One (medium)