algoblazerEarly Access
LearnProblemsLeaderboard
Log inSign up

All problems

‹ Back to map
1 shown · 0/261 solved

Letter Count Similarity

BronzeCommunity Beta
Asked atIBM
Solve problem →
2000ms256MBAdded Sep 1, 2026

You are given two string arrays s and t of the same length n; every string consists of lowercase English letters. The strings are paired by index: (s[i], t[i]).

Two strings are similar if, for every letter from a to z, the number of times the letter occurs in one string differs from the number of times it occurs in the other by at most 3.

Return an array of n strings where element i is "YES" if s[i] and t[i] are similar and "NO" otherwise.

Examples

Example 1

Input: s = ["aabaab","aaaaabb"], t = ["bbabbc","abbbbbb"]
Output: ["YES","NO"]
Explanation: Pair 0: a occurs 4 vs 1 times (difference 3), b 2 vs 4 (2), c 0 vs 1 (1), never more than 3, so YES. Pair 1: a occurs 5 vs 1 times (difference 4), so NO.

Example 2

Input: s = ["abc"], t = ["cba"]
Output: ["YES"]
Explanation: Identical letter counts.

Constraints

  • 1≤n≤51 \leq n \leq 51≤n≤5
  • 1≤1 \leq1≤ length of every string ≤105\leq 10^5≤105
  • all strings consist of lowercase English letters

Details

Solved by3 people
Time limit2000ms
Memory256MB
AddedSep 1, 202611 days ago