Skip to content

Practice Change Minimum Characters to Satisfy One of Three Conditions

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1737
LeetCode Problem

Change Minimum Characters to Satisfy One of Three Conditions

Problem Statement

A move changes one character of lowercase string a or b to any lowercase letter. Minimize moves needed to achieve at least one condition: every a letter is alphabetically smaller than every b letter; every b letter is smaller than every a letter; or both strings consist entirely of the same single letter. Return that minimum.

Source: Change Minimum Characters to Satisfy One of Three Conditions on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
a = "aba", b = "caa"
Output
2

# Example 2

Input
a = "dabadd", b = "cda"
Output
3

Constraints

1 <= a.length, b.length <= 10^5
a and b consist only of lowercase letters.

Related LeetCode Problems

Practice more problems similar to Change Minimum Characters to Satisfy One of Three Conditions.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.