Remove Every Repeated-Value Run from a Sorted List

Quick Overview

Remove every repeated-value run from a sorted linked list, leaving only values that originally appeared once.

Remove Every Repeated-Value Run from a Sorted List

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

### Problem Given the head of a sorted singly linked list, remove every node whose value appears more than once in the original list. Return the head of the sorted list containing only values that originally occurred exactly once. A repeated value contributes no surviving node. The supplied `ListNode` has `val` and `next` fields. Preserve its pointer interface: ```cpp ListNode* deleteDuplicates(ListNode* head); ``` Brackets display a chain's values, not an array argument or array return. ### Examples ```text Input: head = [-2,-2,0,3,3,8] Output list: [0,8] ``` ```text Input: head = [4,4] Output list: [] ``` ### Constraints - The list has between 0 and 300 nodes. - Node values are between -100 and 100, inclusive. - The input is sorted in ascending order, with equal values allowed.

Overview: Remove every repeated-value run from a sorted linked list, leaving only values that originally appeared once.

Amazon logo
Amazon
Jul 20, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

Problem

Given the head of a sorted singly linked list, remove every node whose value appears more than once in the original list. Return the head of the sorted list containing only values that originally occurred exactly once. A repeated value contributes no surviving node.

The supplied ListNode has val and next fields. Preserve its pointer interface:

ListNode* deleteDuplicates(ListNode* head);

Brackets display a chain's values, not an array argument or array return.

Examples

Input: head = [-2,-2,0,3,3,8]
Output list: [0,8]
Input: head = [4,4]
Output list: []

Constraints

  • The list has between 0 and 300 nodes.
  • Node values are between -100 and 100, inclusive.
  • The input is sorted in ascending order, with equal values allowed.