HARDasked at 6 companies

Distinct Subsequences

A hard-tier problem at 50% community acceptance, tagged with String, Dynamic Programming. Reported in interviews at Salesforce and 5 others.

Founder's read

Distinct Subsequences is a hard-tier string DP problem that looks innocent but crushes candidates who don't nail the state definition. The acceptance rate hovers right around 50 percent, meaning half the people who see it live either time out or ship wrong logic. Salesforce, TikTok, Uber, and Coupang have all asked it. The trap is thinking you can just count or use a greedy pass. You need to track how many distinct ways you can form a target string as a subsequence of a source string, and the DP recurrence isn't obvious on first read. If this problem hits your live OA and you blank on the counting trick, StealthCoder solves it in seconds, invisible to the proctor.

Companies asking
6
Difficulty
HARD
Acceptance
50%

Companies that ask "Distinct Subsequences"

If this hits your live OA

Distinct Subsequences is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made for the engineer who has done the work but might still blank with a webcam pointed at him.

Get StealthCoder
What this means

The core pattern is two-pointer DP where you build a table of counts, not just reachability. Most people default to a greedy or naive recursive approach and miss that you're not checking existence, you're enumerating all distinct subsequences. The trick: when characters match, the count at position (i, j) isn't just carry-forward. You have to add the count from the diagonal position because now you can form new subsequences by extending all previous matches. When they don't match, you carry forward the count from above. Edge cases kill fast: empty target (answer is 1), empty source but nonempty target (answer is 0), and handling duplicate characters correctly. This is a counting problem disguised as a string search. StealthCoder is your hedge if the recurrence relation doesn't click during the live assessment.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Distinct Subsequences recycles across companies for a reason. It's hard-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made for the engineer who has done the work but might still blank with a webcam pointed at him. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Distinct Subsequences interview FAQ

Is Distinct Subsequences still asked by big companies?+

Yes. Salesforce, TikTok, Uber, Coupang, MathWorks, and Trilogy all report asking it. The 50 percent acceptance rate suggests it's a high-signal screen. It's not being rotated out. Plan to see it.

What's the core trick everyone misses?+

Treating it as a counting problem, not a search problem. You're not checking if a subsequence exists, you're enumerating distinct ways to form it. When characters match, you add the diagonal count to the carry-forward, not replace. That recurrence is the whole problem.

How does this relate to other DP string problems?+

It sits between Longest Common Subsequence (search-based) and Regex Match (state-based). You need LCS intuition but with a counting lens. If you've drilled wildcard matching or edit distance, the table structure feels familiar but the recurrence is different.

What kills most candidates in the live OA?+

Off-by-one errors in indexing, not handling the empty target edge case (answer is 1, not 0), or building a reachability table instead of a count table. The 50 percent pass rate reflects these mistakes propagating fast.

How long should this take to solve from scratch?+

If you know the pattern, 10 to 15 minutes for a clean implementation. If you're guessing, 25 to 40 minutes and you'll likely ship wrong logic. It's a hard problem because the insight doesn't follow from first principles alone.

Want the actual problem statement? View "Distinct Subsequences" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.