Reported September 2024
Deutsche Bankgreedy

Generate Lexicographically Smallest String

Reported by candidates from Deutsche Bank's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Deutsche Bank OA. Under 2s to a working solution.
Founder's read

Deutsche Bank's September OA included a string manipulation problem asking you to generate the lexicographically smallest string. This is a classic greedy construction problem. The trick isn't complex, but the implementation details matter. You're building a result character by character, and at each step you need to pick the smallest character that still lets you win. StealthCoder will catch you if you blank on the greedy choice or loop logic during the live assessment.

Pattern and pitfall

The pattern is pure greedy. You iterate through possible characters (usually 'a' to 'z' or a given set), and for each position in your result, you pick the smallest character that satisfies the constraints of the problem (likely a remaining character count or a frequency limit). The common pitfall is overthinking or trying a recursive approach when a single forward pass works. You also need to track what characters you've used and ensure you don't violate any bounds. The implementation is straightforward once you see the greedy rule, but under pressure candidates often second-guess whether greedy is correct. Have a mental model ready: if you can always pick the smallest option and never regret it, greedy wins.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill Generate Lexicographically Smallest String cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Deutsche Bank's OA.

Deutsche Bank reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Generate Lexicographically Smallest String FAQ

Is this just sorting or picking characters in order?+

Not quite. Sorting the input doesn't solve it. You're constructing a new string by greedily selecting the lexicographically smallest character at each step while respecting whatever constraint the problem sets. It's a building process, not a rearrangement.

What's the common mistake candidates make?+

Trying to backtrack or use dynamic programming when greedy is enough. Or forgetting to track character usage and picking a character you've already exhausted. Build it once, left to right, and commit to the greedy choice.

How do I know what character to pick at each position?+

Loop through characters in order (smallest first) and check if picking that character lets you complete the rest of the string within bounds. Pick the first one that works. That's the greedy rule.

Does the problem expect a specific language or data structure?+

No language requirement was noted. Use a frequency map or counter to track available characters, and build your result string by appending each greedy choice. Standard libraries handle this fine.

If I blank on the approach during the OA, how do I recover?+

Start with a brute force: iterate characters, build all valid strings, sort, return the smallest. It's slow but correct. Then optimize to greedy once you see the pattern. StealthCoder can show you both paths if you need a reset.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Deutsche Bank.

OA at Deutsche Bank?
Invisible during screen share
Get it