MEDIUMasked at 1 company

String Without AAA or BBB

A medium-tier problem at 45% community acceptance, tagged with String, Greedy. Reported in interviews at Zalando and 0 others.

Founder's read

You need to build a string using only 'a' and 'b' characters without ever creating three consecutive identical letters. Zalando has asked this. The constraint is tighter than it sounds: a greedy approach fails because committing to one character too early can trap you in a state where you can't place anything without violating the rule. You're not writing a parser or matching brackets. You're managing state in real time, picking the next character while remembering what you just placed. Miss the pattern and you'll rebuild twice on a live assessment. StealthCoder solves it invisibly if you blank on the trick.

Companies asking
1
Difficulty
MEDIUM
Acceptance
45%

Companies that ask "String Without AAA or BBB"

If this hits your live OA

String Without AAA or BBB 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 an Amazon engineer who realized the OA tests how well you memorized 200 problems, not how well you code.

Get StealthCoder
What this means

The trap is thinking you can always pick the character you need. Actually, once you place two consecutive identical characters, your next move is forced: you must place the other character. The real trick is that sometimes, even when you're forced to pick one character, that choice still violates the rule if it creates three in a row. When that happens, backtrack or reframe the problem: instead of asking 'what can I place next,' ask 'what sequence of alternations gets me unstuck.' This is greedy with a memory cost. You're tracking the last two characters, and you're iterating through potential constructions, pruning paths that dead-end. Many candidates code a brute-force recursive check, which times out. The efficient path: simulate placement, detect when you're stuck, and strategically inject the other character earlier. StealthCoder handles the edge cases where a naive greedy fails on the live OA.

Pattern tags

The honest play

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

String Without AAA or BBB recycles across companies for a reason. It's medium-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 an Amazon engineer who realized the OA tests how well you memorized 200 problems, not how well you code. Works on HackerRank, CodeSignal, CoderPad, and Karat.

String Without AAA or BBB interview FAQ

What makes this medium, not hard?+

The state space is tiny: you only care about the last two characters placed. You're not building a tree or matching nested structures. But the greedy insight isn't obvious, so candidates often code inefficient recursion. That 44.5% acceptance rate reflects the gap between 'I can check if a string is valid' and 'I can efficiently construct one.'

Why does the greedy approach fail?+

Greedy says 'always prefer the character that gets me closer to the target length.' But if you commit to one character twice, you're forced to place the other next. If the other character was just placed, you violate the rule. You need lookahead or backtracking, not pure greedy.

Do I need to handle impossibility?+

The problem statement defines when a solution exists and when it doesn't. Read the input spec carefully. If n is very large, some character distributions might be infeasible. Your code should either return a valid string or signal that none exists, depending on the exact problem version.

Is this still asked at Zalando?+

Zalando is the only reported company in the dataset for this problem. It's a focused interview signal: they want to see if you can recognize a state-machine constraint and code a solution that respects it without brute force.

How do String and Greedy topics connect here?+

You're building a string character by character, which is the String part. The Greedy label refers to the insight that you should push one character as far as possible before switching. But that insight only works if you understand the forced-move constraint, so it's greedy with a twist.

Want the actual problem statement? View "String Without AAA or BBB" 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.