Problem · Array
String-Pair Frequency Similarity
Learn this problemProblem statement
You are given two arrays of strings, s and t, each of length n. Each pair (s[i], t[i]) contains two lowercase English strings.
Two strings are considered similar when:
- Every letter
xfrom'a'through'z'is considered. - The absolute difference between the number of times
xappears in the two strings is at most3.
For each pair (s[i], t[i]), check whether the strings are similar. Return an array of n elements where each element is:
"YES"if the pair is similar."NO"otherwise.
Function
areSimilar(s: String[], t: String[]) → String[]Examples
Example 1
s = ["aabaab","aaaaabb"]t = ["bbabbc","abbbbbb"]return = ["YES","NO"]| Letter | s[0] count | t[0] count | Difference |
|---|---|---|---|
a | 4 | 1 | 3 |
b | 2 | 4 | 2 |
c | 0 | 1 | 1 |
| Letter | s[1] count | t[1] count | Difference |
|---|---|---|---|
a | 5 | 1 | 4 |
b | 2 | 6 | 4 |
The numbers of occurrences of a, b, and c in s[0] and t[0] never differ by more than 3, so this pair is similar. In s[1] and t[1], both a and b violate the condition, so this pair is not similar.
Constraints
1 <= s.length = t.length <= 5.- Each string contains only lowercase English letters.
- Every string has length from
1through100000, inclusive.
More IBM problems
- Parent Process NumberOA · Seen Jul 2026
- Request Retry CountOA · Seen Jul 2026
- Count Strictly Increasing Subsequences of Length 3OA · Seen Jul 2026
- Maximum Requests in a Time WindowOA · Seen Jul 2026
- Query Type Frequency WindowOA · Seen Jul 2026
- Minimum Number of Non-Empty Disjoint SegmentsOA · Seen Jul 2026
- Spam Text ClassificationOA · Seen Jul 2026
- Count Ideal NumbersOA · Seen Jun 2026