MEDIUMasked at 2 companies

Smallest Subsequence of Distinct Characters

A medium-tier problem at 62% community acceptance, tagged with String, Stack, Greedy. Reported in interviews at FactSet and 1 others.

Founder's read

You've seen the greedy string problem before, but this one trips up people who solve it half-way. Smallest Subsequence of Distinct Characters asks you to build a string using each unique character exactly once, in the lexicographically smallest order possible. FactSet and ByteDance both ask it. The naive approach (just sort) fails because you can't reorder characters arbitrarily; you can only pick them in the order they appear in the input. If you haven't practiced the monotonic stack trick, the live OA is where you'll hit the wall. StealthCoder solves it in seconds if you blank on the pattern.

Companies asking
2
Difficulty
MEDIUM
Acceptance
62%

Companies that ask "Smallest Subsequence of Distinct Characters"

If this hits your live OA

Smallest Subsequence of Distinct Characters 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. Built by an engineer at a top-10 tech company who can solve these problems cold but didn't want to trust himself in a 90-minute screen share.

Get StealthCoder
What this means

The key insight is greedy plus a stack. You maintain a stack of characters you've already chosen, and for each new character, you pop characters from the stack if they're greater than the current character AND they appear later in the string (so you can grab them again). This requires preprocessing to count remaining occurrences. Most candidates either skip the lookahead check and produce wrong output, or they forget the stack entirely and try a recursive mess. The 62% acceptance rate reflects this. It's a classic case where the intuition (greedy pick smaller) is right, but the implementation (monotonic stack with occurrence counting) separates preparation from guessing. If you haven't drilled the pattern, StealthCoder is your safety net during the timed assessment.

Pattern tags

The honest play

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

Smallest Subsequence of Distinct Characters recycles across companies for a reason. It's medium-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. Built by an engineer at a top-10 tech company who can solve these problems cold but didn't want to trust himself in a 90-minute screen share. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Smallest Subsequence of Distinct Characters interview FAQ

Is this problem harder than standard greedy string problems?+

Yes. Standard greedy string sorts globally; this one requires you to respect input order while being greedy about lexicographic choice. The monotonic stack trick is not obvious without seeing it once. The 62% acceptance rate confirms it trips up interview candidates.

What's the main mistake people make?+

Forgetting to check if a character appears later before popping it from the stack. Without that lookahead, you prune characters you can't recover. The second mistake is not using a stack at all, treating it as a simple sorting problem, which violates the subsequence constraint.

Does ByteDance or FactSet ask this frequently?+

Both companies have reportedly asked it, though it's not the highest-frequency problem across their loops. It's solid OA material, not a guaranteed hit, so prep it as a medium-difficulty string hedge rather than a core focus.

How does this relate to the monotonic stack topic?+

This is a textbook monotonic stack application. You maintain a decreasing stack of characters; when a smaller character arrives, you pop larger ones (if safe to do so). The stack ensures you build the smallest valid result in a single pass, O(n) time.

Can you solve this without a stack?+

Technically yes, using recursion or simulation, but it's inefficient and error-prone under time pressure. The stack approach is the intended solution. If you don't know it going in, you'll either time out or produce wrong output during the live OA.

Want the actual problem statement? View "Smallest Subsequence of Distinct Characters" 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.