Delete Every Value That Repeats in an Unsorted Singly Linked List

Read the full interview experience this question came from →

Quick Overview

Linked list problem: delete every node whose value occurs more than once in an unsorted singly linked list, removing all copies and keeping the remaining nodes in their original order. It tests frequency counting, list traversal and careful handling of removals, including at the head of the list.

Delete Every Value That Repeats in an Unsorted Singly Linked List

Company: Salesforce

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

A singly linked list holds integer values in no particular order. Delete every node whose value occurs more than once anywhere in the list, removing all copies of that value rather than only the extra ones. Keep the remaining nodes in their original relative order and return the resulting list. For the console, the list is passed as `values`, its node values from head to tail, and you return the surviving node values from head to tail in the same form. Return an empty list if no node survives. ### Function Signature ```python def remove_repeated_values(values: List[int]) -> List[int]: ``` ### Rules - A value that occurs exactly once is kept; a value that occurs two or more times is removed entirely. - The relative order of the surviving nodes does not change. ### Constraints - `1 <= len(values) <= 10^5` - `1 <= values[i] <= 10^5` ### Examples **Example 1** ``` Input: values = [4, 7, 4, 9, 1, 7] Output: [9, 1] ``` Values 4 and 7 each occur twice, so all four of those nodes are removed. **Example 2** ``` Input: values = [8, 8, 8] Output: [] ``` **Example 3** ``` Input: values = [5] Output: [5] ```

Overview: Linked list problem: delete every node whose value occurs more than once in an unsorted singly linked list, removing all copies and keeping the remaining nodes in their original order. It tests frequency counting, list traversal and careful handling of removals, including at the head of the list.

Read the full Salesforce Software Engineer interview experience this question came from

Salesforce logo
Salesforce
Feb 27, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

A singly linked list holds integer values in no particular order. Delete every node whose value occurs more than once anywhere in the list, removing all copies of that value rather than only the extra ones. Keep the remaining nodes in their original relative order and return the resulting list.

For the console, the list is passed as values, its node values from head to tail, and you return the surviving node values from head to tail in the same form. Return an empty list if no node survives.

Function Signature

def remove_repeated_values(values: List[int]) -> List[int]:

Rules

  • A value that occurs exactly once is kept; a value that occurs two or more times is removed entirely.
  • The relative order of the surviving nodes does not change.

Constraints

  • 1 <= len(values) <= 10^5
  • 1 <= values[i] <= 10^5

Examples

Example 1

Input: values = [4, 7, 4, 9, 1, 7]
Output: [9, 1]

Values 4 and 7 each occur twice, so all four of those nodes are removed.

Example 2

Input: values = [8, 8, 8]
Output: []

Example 3

Input: values = [5]
Output: [5]