Reported March 2024
Amazonstring

Maxmimum Times Word Removed

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

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

Amazon threw this at candidates in March 2024, and it's exactly the kind of string manipulation problem that looks simple until you realize you're iterating wrong. You get a string and a word. Remove the word every time it appears, then check if the word still exists in what's left. Count how many removals you made before it can't be removed anymore. StealthCoder catches the off-by-one and loop logic errors when you're three minutes in and blanking on the state machine.

Pattern and pitfall

The trick is that after each removal, the indices shift. You can't just scan once and count. Build a loop: while the word exists in the string, remove it and increment a counter. The catch is handling overlapping removals or cascading effects where removing one instance exposes a new one. Most candidates write a single pass and miss the iteration. Use string replace or a while loop with indexOf. Verify edge cases: empty string, word equals string, word appears multiple times in a chain. StealthCoder feeds you the exact loop structure when the pressure mounts.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Maxmimum Times Word Removed 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 passed his OA cold and still thinks the filter is broken.

Get StealthCoder

Related leaked OAs

⏵ The honest play

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

Amazon reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Maxmimum Times Word Removed FAQ

Do I need to handle overlapping word instances?+

Yes. After you remove one instance, the remaining characters can form the word again. For example, if you're removing 'AA' from 'AAA', the first removal leaves 'A', but you might form it again. Use a while loop, not a for loop.

Should I use string.replace() or build the string manually?+

Use replace() once per iteration and loop until the word no longer exists. It's cleaner and less error-prone than manual character building. Most languages have efficient string replace. Let the standard library do the work.

What's the time complexity Amazon expects?+

Worst case is O(n * m) where n is string length and m is removal count. If the word keeps reappearing, you may iterate many times. Amazon doesn't penalize this for reasonable inputs. Focus on correctness first.

Is this actually a hard problem or am I overthinking it?+

It's medium difficulty, not hard. The gotcha is the loop logic and remembering to re-scan after each removal. If you code it as a simple while loop with a counter, you'll nail it. The problem tests whether you understand state mutation in strings.

Can I solve this in one pass through the string?+

No. You must re-evaluate after each removal because the string changes. A single pass will miss removals that occur after you've already scanned past them. Commit to the while loop pattern.

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

OA at Amazon?
Invisible during screen share
Get it