HARDasked at 1 company

Smallest K-Length Subsequence With Occurrences of a Letter

A hard-tier problem at 39% community acceptance, tagged with String, Stack, Greedy. Reported in interviews at Deutsche Bank and 0 others.

Founder's read

You need to build a K-length subsequence where a specific letter appears at least X times, and the result is lexicographically smallest. Deutsche Bank has asked this. It's a hard problem with a 39% acceptance rate, so most candidates either miss the greedy insight or implement it wrong. The trick isn't just picking the smallest characters; it's knowing when to skip a character now so you can grab something better later. If you hit this live and freeze on the strategy, StealthCoder solves it invisibly during your assessment.

Companies asking
1
Difficulty
HARD
Acceptance
39%

Companies that ask "Smallest K-Length Subsequence With Occurrences of a Letter"

If this hits your live OA

Smallest K-Length Subsequence With Occurrences of a Letter 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 a senior engineer who knows the OA is theater. This is the script.

Get StealthCoder
What this means

This is a greedy plus monotonic stack problem disguised as a string problem. The naive approach is to sort and pick, but that fails because you need a subsequence (order matters) and a letter frequency floor. The real solution uses a stack to maintain lexicographic order while making space for the required letter. You track remaining characters and remaining quota for the target letter, then decide whether to pop the current top of the stack if it's larger than the incoming character and still appears later. Common failure: not counting remaining characters correctly, or popping too much and missing the frequency requirement. Another trap: greedy character selection without the stack backbone. If this pattern isn't in your muscle memory and you get it in a live OA, you'll be stuck in implementation hell. StealthCoder handles the state management and edge cases in seconds, giving you the working code before you spiral.

Pattern tags

The honest play

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

Smallest K-Length Subsequence With Occurrences of a Letter 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. Built by a senior engineer who knows the OA is theater. This is the script. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Smallest K-Length Subsequence With Occurrences of a Letter interview FAQ

Is this really asked at Deutsche Bank or just one report?+

One company in the data set, Deutsche Bank. That's a solid bank doing serious algorithmic vetting. It's not a Google or Meta problem, so fewer candidates will have drilled it. That's actually the risk: it'll feel unfamiliar in the moment.

What's the actual trick I'm missing if I can't solve it?+

Most people either sort the string (wrong, you need order) or greedily pick characters without a stack (fails the lexicographic constraint). The trick is the monotonic stack: pop larger characters only if they reappear later and you still have quota. It's not intuitive without seeing it.

How does the greedy approach actually work here?+

At each step, you decide: keep the current character or pop the stack top if it's bigger and you can afford to lose it (it reappears later and the required letter still has room). This builds the lexicographically smallest result while respecting the length and frequency constraints.

Why is the acceptance rate so low?+

The problem layers three constraints: K length, X occurrences of a letter, and lexicographic minimality. Most candidates solve one or two but fail the integration. The monotonic stack logic is also easy to get subtly wrong during a timed assessment.

What topics should I have solid before attempting this?+

You need monotonic stack patterns and greedy validation. String manipulation helps. The problem combines Stack, Greedy, and String topics, so if you're weak in any, you'll struggle. Monotonic stack is the heaviest lift.

Want the actual problem statement? View "Smallest K-Length Subsequence With Occurrences of a Letter" 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.