Ctrl K

Close Letter Counts

Easy
You are given two strings first and second (their lengths may differ). For every letter from a to z, count how many times it occurs in each string. Return True if, for every letter, the two counts differ by at most 3, and False if any letter has a gap of 4 or more.
Example 1
first="bananas", second="cabbage" → True

a: 3 vs 2, n: 2 vs 0, s: 1 vs 0, b: 1 vs 2, c, g, e: 0 vs 1, so no gap exceeds 3.

Example 2
first="zzzzk", second="kkkkk" → False

z appears 4 times in the first string and never in the second.

Constraints
  • 1 ≤ len(first), len(second) ≤ 100
  • Strings consist of lowercase Latin letters
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsNote From Clipped Letters EasyFirst One-Off Letter EasyWords Heard Only Once EasyWords From Letter Tiles EasyBalloon Signs From Letters Easy
loading Python…
Input
first="bananas", second="cabbage"
Expected
True

Run checks the first 3 tests in your browser. Submit checks all 146 tests on the server, hidden ones included.