1737. Change Minimum Characters to Satisfy One of Three Conditions Medium
1/**
2 * [1737] Change Minimum Characters to Satisfy One of Three Conditions
3 *
4 * 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.
5 * Your goal is to satisfy one of the following three conditions:
6 *
7 * Every letter in a is strictly less than every letter in b in the alphabet.
8 * Every letter in b is strictly less than every letter in a in the alphabet.
9 * Both a and b consist of only one distinct letter.
10 *
11 * Return the minimum number of operations needed to achieve your goal.
12 *
13 * Example 1:
14 *
15 * Input: a = "aba", b = "caa"
16 * Output: 2
17 * Explanation: Consider the best way to make each condition true:
18 * 1) Change b to "ccc" in 2 operations, then every letter in a is less than every letter in b.
19 * 2) Change a to "bbb" and b to "aaa" in 3 operations, then every letter in b is less than every letter in a.
20 * 3) Change a to "aaa" and b to "aaa" in 2 operations, then a and b consist of one distinct letter.
21 * The best way was done in 2 operations (either condition 1 or condition 3).
22 *
23 * Example 2:
24 *
25 * Input: a = "dabadd", b = "cda"
26 * Output: 3
27 * Explanation: The best way is to make condition 1 true by changing b to "eee".
28 *
29 *
30 * Constraints:
31 *
32 * 1 <= a.length, b.length <= 10^5
33 * a and b consist only of lowercase letters.
34 *
35 */
36pub struct Solution {}
37
38// problem: https://leetcode.com/problems/change-minimum-characters-to-satisfy-one-of-three-conditions/
39// discuss: https://leetcode.com/problems/change-minimum-characters-to-satisfy-one-of-three-conditions/discuss/?currentPage=1&orderBy=most_votes&query=
40
41// submission codes start here
42
43impl Solution {
44 pub fn min_characters(a: String, b: String) -> i32 {
45 0
46 }
47}
48
49// submission codes end
50
51#[cfg(test)]
52mod tests {
53 use super::*;
54
55 #[test]
56 fn test_1737() {
57 }
58}
59
Back
© 2025 bowen.ge All Rights Reserved.