Reported April 2024
Microsofthash table

Min Str without Reapting Chars

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

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

Microsoft hit you with a string problem in April 2024, and the title's a bit mangled but the task is clear: find the minimum length string after removing characters such that no character repeats. You're not studying anymore. You have an OA in 48 hours. The pattern here is greedy with a hash table or set to track what you've already kept. StealthCoder will have your back if the approach blanks during the live assessment, but knowing the core trick now saves you panic time.

Pattern and pitfall

The core move is greedy: iterate through the string and keep each character the first time you see it, skip it every time after. You build a result string or use a set to track included characters. The trick candidates miss is thinking they need to optimize which copy of a repeated character to keep. You don't. First occurrence always wins because removing it later costs you nothing and removing others might cost you more. If the problem wanted min length after deletions to make the string have no adjacent repeats, that's different, but the title suggests distinctness. Use a set for O(1) lookups. The pitfall: overthinking the order or trying to rearrange. The win: one pass, greedy, done.

The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.

If this hits your live OA

You can drill Min Str without Reapting Chars 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 for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.

Get StealthCoder

Related leaked OAs

⏵ The honest play

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

Microsoft reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Min Str without Reapting Chars FAQ

Is this really just keeping the first occurrence of each character?+

Yes. Iterate left to right, add a character to your result if you haven't seen it before, skip if you have. One pass, O(n) time. No rearranging, no priority swaps. Greedy works because you never benefit from choosing a later copy.

What's the trick Microsoft is testing here?+

Recognizing that a greedy approach is sufficient and resisting the urge to optimize character selection. Also, clean use of a set or hash table for membership tracking. If you overthink it, you'll code a slow solution that times out.

Can I solve this without a set?+

Yes, use a boolean array of size 26 (lowercase) or 52 (mixed case) or a dict. Whatever fits your language. The point is O(1) lookup. A set is cleanest in Python.

What if the string is empty or has one character?+

Edge cases. Empty string returns empty. Single character returns that character. These usually don't trip the main logic, but test them anyway. They're free confidence points.

How do I prepare for this in 24 hours?+

Know one string and set solution cold. Write it out by hand twice. Understand why greedy is optimal here. If you blank during the OA, StealthCoder reads the prompt and gives you the pattern instantly. That's your safety net.

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

OA at Microsoft?
Invisible during screen share
Get it