Skip to content

Practice Check Whether Two Strings are Almost Equivalent

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

Easy#2068
LeetCode Problem

Check Whether Two Strings are Almost Equivalent

Problem Statement

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. Given two strings word1 and word2, each of length n, return true if word1 and word2 are almost equivalent, or false otherwise. The frequency of a letter x is the number of times it occurs in the string.

Source: Check Whether Two Strings are Almost Equivalent on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
word1 = "aaaa", word2 = "bccb"
Output
false

# Example 2

Input
word1 = "abcdeef", word2 = "abaaacc"
Output
true

# Example 3

Input
word1 = "cccddabba", word2 = "babababab"
Output
true

Constraints

n == word1.length == word2.length
1 <= n <= 100
word1 and word2 consist only of lowercase English letters.

Related LeetCode Problems

Practice more problems similar to Check Whether Two Strings are Almost Equivalent.

Review your practice with PhantomCodeAI

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