Reported September 2026
Bloombergcounting

Minimum Replacements to Make Two Strings Anagrams

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

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

Bloomberg reported this one in September 2026, and the 10^5 length cap is the first thing to read. Trying replacements position by position or permuting characters dies instantly, so you need a counting answer in linear time. It's a frequency-count problem dressed up as an anagram question. If your head goes blank mid-assessment, StealthCoder runs invisibly on your desktop as a safety net and reads the problem for you. But the idea is small enough that you can own it before the invite even opens.

The problem

Return the minimum number of positions in first whose characters must be replaced so first and second are anagrams. Return -1 if their lengths differ.

Function
minimumAnagramReplacements(first: String, second: String) → int

Examples
Example 1
first = "bab"
second = "aba"
return = 1
Replacing one b with a equalizes the character counts.

Constraints
Both strings contain lowercase English letters.
Each length is at most 10^5.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick: anagrams share identical character counts, so you only care about how the counts differ. Build a 26-slot count array for the first string. Walk the second string and decrement. Any positive leftover in the array is a character that first has too many of, and each one must be replaced by something second needs. Sum the positive leftovers and that's your answer. Check lengths first and return -1 if they differ. Common pitfall: summing absolute differences and forgetting to halve it, which double counts every mismatch. Another one is sorting both strings and comparing positions, which gives the wrong answer. With the example bab and aba, b has count 2 versus 1, so one extra b, so one replacement. That's O(n) time and O(1) space. If you freeze live, StealthCoder is the hedge that hands you this logic on the spot.

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 Minimum Replacements to Make Two Strings Anagrams 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 minimum number of steps to make two strings anagram. If you have time before the OA, drill that.

⏵ The honest play

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

Bloomberg 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.

Minimum Replacements to Make Two Strings Anagrams FAQ

What's the trick for Minimum Replacements to Make Two Strings Anagrams?+

Count letter frequencies, not positions. Compare the counts of first against second and sum only the surplus on one side. Each surplus character in first needs exactly one replacement. Check for unequal lengths up front and return -1 before doing anything else.

How hard is this one really?+

Easy to medium. The code is about ten lines once you see it's a counting problem. The difficulty is resisting the urge to simulate swaps or sort. If you've seen a basic anagram check, you've seen the core of this.

Why does brute force fail here?+

Lengths go up to 10^5, so anything quadratic or factorial is out. Trying replacement combinations explodes immediately. A single pass to build counts plus a 26-slot scan runs in linear time and fits comfortably.

Do I sum absolute differences or just the positives?+

Just the positives, or sum absolute differences and divide by two. Since lengths are equal, total surplus equals total deficit. Summing absolute values without halving counts every mismatch twice and gives double the right answer.

How do I prepare for this in 48 hours?+

Write the solution from scratch twice using a 26-int array. Test with bab and aba, identical strings, and different lengths. Then do a couple of similar frequency-count string problems. That covers this pattern and its common variants.

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

OA at Bloomberg?
Invisible during screen share
Get it