2186. Minimum Number of Steps to Make Two Strings Anagram II Medium

@problem@discussion
#Hash Table#String#Counting



1/**
2 * [2186] Minimum Number of Steps to Make Two Strings Anagram II
3 *
4 * You are given two strings s and t. In one step, you can append any character to either s or t.
5 * Return the minimum number of steps to make s and t anagrams of each other.
6 * An anagram of a string is a string that contains the same characters with a different (or the same) ordering.
7 *  
8 * Example 1:
9 * 
10 * Input: s = "<u>lee</u>tco<u>de</u>", t = "co<u>a</u>t<u>s</u>"
11 * Output: 7
12 * Explanation: 
13 * - In 2 steps, we can append the letters in "as" onto s = "leetcode", forming s = "leetcode<u>as</u>".
14 * - In 5 steps, we can append the letters in "leede" onto t = "coats", forming t = "coats<u>leede</u>".
15 * "leetcodeas" and "coatsleede" are now anagrams of each other.
16 * We used a total of 2 + 5 = 7 steps.
17 * It can be shown that there is no way to make them anagrams of each other with less than 7 steps.
18 * 
19 * Example 2:
20 * 
21 * Input: s = "night", t = "thing"
22 * Output: 0
23 * Explanation: The given strings are already anagrams of each other. Thus, we do not need any further steps.
24 * 
25 *  
26 * Constraints:
27 * 
28 * 	1 <= s.length, t.length <= 2 * 10^5
29 * 	s and t consist of lowercase English letters.
30 * 
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/minimum-number-of-steps-to-make-two-strings-anagram-ii/
35// discuss: https://leetcode.com/problems/minimum-number-of-steps-to-make-two-strings-anagram-ii/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40    pub fn min_steps(s: String, t: String) -> i32 {
41        0
42    }
43}
44
45// submission codes end
46
47#[cfg(test)]
48mod tests {
49    use super::*;
50
51    #[test]
52    fn test_2186() {
53    }
54}
55


Back
© 2025 bowen.ge All Rights Reserved.