You are given two strings a and b consisting only of lowercase English letters. Your mission is to transform these strings with the minimum number of character changes to satisfy one of three winning conditions:
- Alphabetical Dominance (a < b): Every character in string
amust be strictly less than every character in stringbalphabetically - Alphabetical Dominance (b < a): Every character in string
bmust be strictly less than every character in stringaalphabetically - Uniform Strings: Both strings must consist of only one distinct character (they can be different characters)
In one operation, you can change any character in either string to any lowercase letter. Your goal is to find the minimum number of operations needed to achieve any one of these three conditions.
Example: If a = "aba" and b = "caa", you could change one character to make a = "aaa" and b = "aaa" (condition 3), requiring just 1 operation.
Input & Output
Visualization
Time & Space Complexity
Single pass to count frequencies O(n + m), then O(26) to try all splits and characters
Only using fixed-size arrays of length 26 for character frequencies
Constraints
- 1 โค a.length, b.length โค 105
- a and b consist only of lowercase English letters
- The strings are guaranteed to be non-empty