2068. Check Whether Two Strings are Almost Equivalent Easy
1/**
2 * [2068] Check Whether Two Strings are Almost Equivalent
3 *
4 * Two strings word1 and word2 are considered almost equivalent if the differences between the frequencies of each letter from 'a' to 'z' between word1 and word2 is at most 3.
5 * Given two strings word1 and word2, each of length n, return true if word1 and word2 are almost equivalent, or false otherwise.
6 * The frequency of a letter x is the number of times it occurs in the string.
7 *
8 * Example 1:
9 *
10 * Input: word1 = "aaaa", word2 = "bccb"
11 * Output: false
12 * Explanation: There are 4 'a's in "aaaa" but 0 'a's in "bccb".
13 * The difference is 4, which is more than the allowed 3.
14 *
15 * Example 2:
16 *
17 * Input: word1 = "abcdeef", word2 = "abaaacc"
18 * Output: true
19 * Explanation: The differences between the frequencies of each letter in word1 and word2 are at most 3:
20 * - 'a' appears 1 time in word1 and 4 times in word2. The difference is 3.
21 * - 'b' appears 1 time in word1 and 1 time in word2. The difference is 0.
22 * - 'c' appears 1 time in word1 and 2 times in word2. The difference is 1.
23 * - 'd' appears 1 time in word1 and 0 times in word2. The difference is 1.
24 * - 'e' appears 2 times in word1 and 0 times in word2. The difference is 2.
25 * - 'f' appears 1 time in word1 and 0 times in word2. The difference is 1.
26 *
27 * Example 3:
28 *
29 * Input: word1 = "cccddabba", word2 = "babababab"
30 * Output: true
31 * Explanation: The differences between the frequencies of each letter in word1 and word2 are at most 3:
32 * - 'a' appears 2 times in word1 and 4 times in word2. The difference is 2.
33 * - 'b' appears 2 times in word1 and 5 times in word2. The difference is 3.
34 * - 'c' appears 3 times in word1 and 0 times in word2. The difference is 3.
35 * - 'd' appears 2 times in word1 and 0 times in word2. The difference is 2.
36 *
37 *
38 * Constraints:
39 *
40 * n == word1.length == word2.length
41 * 1 <= n <= 100
42 * word1 and word2 consist only of lowercase English letters.
43 *
44 */
45pub struct Solution {}
46
47// problem: https://leetcode.com/problems/check-whether-two-strings-are-almost-equivalent/
48// discuss: https://leetcode.com/problems/check-whether-two-strings-are-almost-equivalent/discuss/?currentPage=1&orderBy=most_votes&query=
49
50// submission codes start here
51
52impl Solution {
53 pub fn check_almost_equivalent(word1: String, word2: String) -> bool {
54 false
55 }
56}
57
58// submission codes end
59
60#[cfg(test)]
61mod tests {
62 use super::*;
63
64 #[test]
65 fn test_2068() {
66 }
67}
68
Back
© 2025 bowen.ge All Rights Reserved.