FastPrepMinimum Replacements to Make Two Strings Anagrams
Problems/Minimum Replacements to Make Two Strings Anagrams

Minimum Replacements to Make Two Strings Anagrams

Bloomberg LP logoBloomberg LP● EasyNEW GRADFULLTIMEPHONE SCREENONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a first-hand Bloomberg 2019 new-grad onsite. This practice contract uses lowercase letters and -1 for unequal lengths.

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.

More Bloomberg LP problems

  • Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Sparse Vector and Matrix OperationsPHONE SCREEN · Seen Oct 2026
  • Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
All Bloomberg LP interview questionsSee Bloomberg LP hiring insights
Saved
class Solution {
    public int minimumAnagramReplacements(String first, String second) {
      // Write your code here.
    }
}
Checking account…