PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Salesforce

Remove duplicates and find constrained longest subsequence

Last updated: Jun 10, 2026

Quick Overview

This question evaluates data structure manipulation and string-processing competencies, specifically linked-list deduplication and finding the longest string that is both a subsequence of one string and a substring of another.

  • easy
  • Salesforce
  • Coding & Algorithms
  • Software Engineer

Remove duplicates and find constrained longest subsequence

Company: Salesforce

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Take-home Project

You are given two independent coding tasks. ## Task 1: Remove duplicates from a linked list Given the head of a **singly linked list** (not necessarily sorted), remove duplicate values so that **each value appears only once**, keeping the **first occurrence** of each value and **preserving the original relative order** of the remaining nodes. - **Input:** `head` of a singly linked list where each node has fields `val` and `next`. - **Output:** the head of the de-duplicated linked list. - **Constraints (example):** number of nodes `n` up to `10^5`; node values fit in 32-bit signed int. **Example** - Input: `1 -> 3 -> 1 -> 2 -> 3 -> null` - Output: `1 -> 3 -> 2 -> null` ## Task 2: Longest subsequence of x that is a substring of y Given two strings `x` and `y`, find **one** longest string `s` such that: 1. `s` is a **subsequence** of `x` (characters chosen in order, not necessarily contiguous), and 2. `s` is a **substring** of `y` (contiguous segment of `y`). If multiple answers have the same maximum length, you may return **any one** of them. - **Input:** strings `x`, `y` - **Output:** a string `s` meeting the conditions with maximum possible length (or an empty string if no non-empty solution exists). - **Constraints (example):** `1 ≤ |x|, |y| ≤ 2000`; characters are lowercase English letters. **Example** - `x = "abac"`, `y = "zzbaczz"` - One valid output: `"bac"` (it is a subsequence of `x` and a substring of `y`).

Quick Answer: This question evaluates data structure manipulation and string-processing competencies, specifically linked-list deduplication and finding the longest string that is both a subsequence of one string and a substring of another.

Related Interview Questions

  • Minimum Sum of Weekly Maximum Costs - Salesforce
  • 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)
Salesforce logo
Salesforce
Jan 22, 2026, 12:00 AM
Software Engineer
Take-home Project
Coding & Algorithms
31
0
Loading...

You are given two independent coding tasks.

Task 1: Remove duplicates from a linked list

Given the head of a singly linked list (not necessarily sorted), remove duplicate values so that each value appears only once, keeping the first occurrence of each value and preserving the original relative order of the remaining nodes.

  • Input: head of a singly linked list where each node has fields val and next .
  • Output: the head of the de-duplicated linked list.
  • Constraints (example): number of nodes n up to 10^5 ; node values fit in 32-bit signed int.

Example

  • Input: 1 -> 3 -> 1 -> 2 -> 3 -> null
  • Output: 1 -> 3 -> 2 -> null

Task 2: Longest subsequence of x that is a substring of y

Given two strings x and y, find one longest string s such that:

  1. s is a subsequence of x (characters chosen in order, not necessarily contiguous), and
  2. s is a substring of y (contiguous segment of y ).

If multiple answers have the same maximum length, you may return any one of them.

  • Input: strings x , y
  • Output: a string s meeting the conditions with maximum possible length (or an empty string if no non-empty solution exists).
  • Constraints (example): 1 ≤ |x|, |y| ≤ 2000 ; characters are lowercase English letters.

Example

  • x = "abac" , y = "zzbaczz"
  • One valid output: "bac" (it is a subsequence of x and a substring of y ).

Submit Your Answer to Earn 20XP

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,000+ 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.