Change Minimum Characters to Satisfy One of Three Conditions
You are given two strings a and b that consist of lowercase letters. In one operation, you can change any character in a or b to any lowercase letter.
Your goal is to satisfy one of the following three conditions:
- Every letter in
ais strictly less than every letter inbin the alphabet. - Every letter in
bis strictly less than every letter inain the alphabet. - Both
aandbconsist of only one distinct letter.
Return the minimum number of operations needed to achieve your goal.
Example 1
Input
a = "aba", b = "caa"Output
2The best way takes 2 operations, either by making every letter in
a strictly less than every letter in b or by making both strings consist of one distinct letter.Example 2
Input
a = "dabadd", b = "cda"Output
3The best way is to make condition 1 true by changing
b to "eee".Constraints
- 1 <= a.length, b.length <= 10^5
- a and b consist only of lowercase letters.