FastPrepMinimum Replacements to Make Two Strings Anagrams

Minimum Replacements to Make Two Strings Anagrams

Bloomberg LP logoBloomberg LP● EasyNEW GRADFULLTIMEPHONE SCREENONSITE INTERVIEW
Learn

Problem statement

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

See Bloomberg LP hiring insights
public int minimumAnagramReplacements(String first, String second) {
  // Write your code here.
}
first"bab"
second"aba"
expected1
Checking account…