← All questions
MediumCoding
Smallest Subsequence of Distinct Characters
Asked at
PhonePe
1Give yourself 5 minutes
2Answer out loud, not in your head
3Then compare with the answer below
0
Stuck? Show a way to structure it+
- 01Record each character's final occurrence.
- 02Scan left to right while tracking characters already in the stack.
- 03Pop a larger stack character only if it appears again later.
- 04Push the current unseen character and join the stack.
Reference answer
Then expect these follow-ups
How is this related to Remove Duplicate Letters?
Tests: pattern recognition
Why is every pop safe?
Tests: greedy proof
Free to read · better with Enzo
Practice this out loud with Enzo
Enzo runs it as a mock interview, pushes back with follow-ups, and grades you on the rubric.
Next question