Reported August 2024
Microsoftstack

Shortest Possible Length

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's August OA included a string manipulation problem called Shortest Possible Length. You've got a string and need to reduce it to its minimum viable form by removing adjacent duplicate characters that match. This isn't a hard problem algorithmically, but the trick is knowing which data structure saves you from a slow, messy implementation. If you blank on the pattern, StealthCoder will read the problem on screen and show you the solution in real time without the proctor seeing a thing.

Pattern and pitfall

The pattern here is stack-based removal. You iterate through the string and push characters onto a stack. Before you push, check if the top of the stack matches the current character. If it does, pop instead of push. If it doesn't, push. By the end, your stack contains only the characters that survived. The common mistake is trying to use indices and splice the original string, which gets messy and slow in a loop. A stack is clean, O(n) time, O(n) space, and the code writes itself. This is a classic interview pattern disguised as a string problem.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill Shortest Possible Length 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. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as remove all adjacent duplicates in string. If you have time before the OA, drill that.

⏵ The honest play

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

Microsoft reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Shortest Possible Length FAQ

Is this problem actually hard?+

No. The algorithmic complexity is trivial once you see the stack pattern. The real test is whether you can recognize the pattern under pressure and code it without bugs. Most failures come from trying to mutate the string directly instead of using a stack.

What languages does Microsoft allow?+

The input didn't specify. Most Microsoft OAs accept Python, Java, C++, and JavaScript. Assume you can code in your strongest language. The logic doesn't change across languages; the stack operation is the same.

How much time do I have?+

Not stated in the problem report. Typically Microsoft gives 30-45 minutes per problem. This one should take 10-15 minutes to code correctly once you see the pattern. Budget extra time for edge cases like empty strings or single characters.

What are the edge cases I should test?+

Empty string (return empty), single character (return as-is), entire string cancels (return empty), no matches (return original), alternating characters like 'ababab' (reduces to empty or single char depending on logic).

Is this problem still asked at Microsoft?+

Yes, reported in August 2024. Stack-based removal and string reduction are bread-and-butter patterns in interviews. If you see a problem about removing or collapsing adjacent elements, stack is almost always the answer.

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