PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Salesforce

Remove duplicates from a singly linked list

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of singly linked list data structures and in-place node manipulation to remove repeated values while preserving relative order, testing competencies in pointer management and duplicate-detection.

  • medium
  • Salesforce
  • Coding & Algorithms
  • Software Engineer

Remove duplicates from a singly linked list

Company: Salesforce

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: HR Screen

You are given the head of a **singly linked list** of integers. Modify the list **in place** so that it contains **only the first occurrence** of each value (i.e., remove any node whose value has already appeared earlier in the list). - Each node has fields: - `data` (integer) - `next` (reference to next node, or `null` at the tail) - The **relative order** of the remaining nodes must stay the same. Return the head of the updated linked list. ### Examples 1. Input: `3 -> 4 -> 3 -> 6` Output: `3 -> 4 -> 6` 2. Input: `3 -> 4 -> 3 -> 2 -> 6 -> 1 -> 2 -> 6` Output: `3 -> 4 -> 2 -> 6 -> 1`

Quick Answer: This question evaluates understanding of singly linked list data structures and in-place node manipulation to remove repeated values while preserving relative order, testing competencies in pointer management and duplicate-detection.

Related Interview Questions

  • Solve Two OA Coding Problems - Salesforce (medium)
  • Maximize events attended given date ranges - Salesforce (medium)
  • Implement common data-structure and JS tasks - Salesforce (medium)
  • Minimize operations to reduce integer to zero - Salesforce (medium)
  • Implement an LFU cache with O(1) operations - Salesforce (medium)
Salesforce logo
Salesforce
Nov 13, 2025, 12:00 AM
Software Engineer
HR Screen
Coding & Algorithms
7
0

You are given the head of a singly linked list of integers. Modify the list in place so that it contains only the first occurrence of each value (i.e., remove any node whose value has already appeared earlier in the list).

  • Each node has fields:
    • data (integer)
    • next (reference to next node, or null at the tail)
  • The relative order of the remaining nodes must stay the same.

Return the head of the updated linked list.

Examples

  1. Input: 3 -> 4 -> 3 -> 6
    Output: 3 -> 4 -> 6
  2. Input: 3 -> 4 -> 3 -> 2 -> 6 -> 1 -> 2 -> 6
    Output: 3 -> 4 -> 2 -> 6 -> 1

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Salesforce•More Software Engineer•Salesforce Software Engineer•Salesforce Coding & Algorithms•Software Engineer Coding & Algorithms
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.