← Salesforce Interview Insights

Salesforce·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Salesforce SWE interview with a linked list problem. Pretty standard coding round, nothing too wild, but the in-place constraint is the kind of thing that trips you up if you're not paying attention.

Questions Asked (1)

Q1

Given the head of a singly linked list, remove all duplicate nodes in-place so only the first occurrence of each value remains, preserving the original order.

Algorithms & Data Structures
Author's notes

My first instinct was a set to track seen values and just relink nodes as I walked the list.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a hash set to track seen values while traversing the list with a pointer, removing any node whose value is already in the set. Alternatively, if the list is sorted, use a two-pointer technique to skip duplicates in O(1) space. Clarify with the interviewer whether the list is sorted and discuss trade-offs between time and space.

Pro tip: Always clarify if the list is sorted; if not, a hash set is optimal, but mention that sorting first would change the order and is not allowed. Also, handle edge cases like empty list or single node upfront.

1. Clarify requirements and constraints

Ask if the list is sorted, if duplicates are based on value only, and if we can use extra space. Confirm that order must be preserved and removal is in-place.

2. Choose the right approach

If sorted, use two pointers to skip duplicates in O(n) time and O(1) space. If unsorted, use a hash set to track seen values, requiring O(n) space.

3. Walk through the algorithm

For hash set: initialize a dummy node pointing to head, traverse with prev and curr. If curr.val in set, skip curr by prev.next = curr.next; else add to set and move prev. For two pointers: use current and runner to skip duplicates.

4. Handle edge cases

Consider empty list, single node, all duplicates, and duplicates at head or tail. Ensure the head is updated correctly if the first node is removed.

5. Analyze complexity and test

State time and space complexity. Walk through a small example to verify correctness, and mention potential follow-ups like removing duplicates from an unsorted list without extra space (not possible in O(n) time).

Key Points to Mention

  • Time and space complexity trade-offs: hash set O(n) time and O(n) space vs. two-pointer O(n) time and O(1) space for sorted lists.
  • In-place modification: updating next pointers without creating new nodes.
  • Edge cases: empty list, single node, duplicates at head, all nodes duplicates.
  • Use of dummy node to simplify removal of head node.
  • Preservation of original order: only first occurrence remains.
  • Clarifying questions: sorted vs unsorted, memory constraints, definition of duplicate (value vs node).

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.