You're given two strings s and t of equal length. Your goal is to transform string t into an anagram of string s by replacing characters in t.
In each step, you can choose any character in t and replace it with any other character. An anagram contains the same characters with the same frequencies, but possibly in different positions.
Example: If s = "bab" and t = "aba", they're already anagrams, so 0 steps are needed. If s = "leetcode" and t = "practice", we need to replace some characters in t to match the character frequencies of s.
Return the minimum number of character replacements needed to make t an anagram of s.
Input & Output
Visualization
Time & Space Complexity
Single pass through both strings of length n
Hash map stores at most 26 characters (constant space)
Constraints
- 1 โค s.length โค 5 ร 104
- s.length == t.length
- s and t consist of lowercase English letters only
- Both strings have the same length