Ctrl K

Block Letter Digest

Medium
A string word of lowercase English letters is cut into consecutive blocks of exactly size characters each (the length of word is a multiple of size). Every letter has a weight equal to its zero-based position in the alphabet: a weighs 0, b weighs 1, …, z weighs 25. Each block is squeezed into a single letter: add up the weights of its letters, take the sum modulo 26 and turn that number back into a letter by the same rule. Return the string made of the digests of all blocks, in the order the blocks appear in word.
Example 1
word="bcadzz", size=2 → 'ddy'

Blocks: "bc" → 1 + 2 = 3 → d; "ad" → 0 + 3 = 3 → d; "zz" → 25 + 25 = 50, 50 mod 26 = 24 → y.

Example 2
word="code", size=4 → 'x'

A single block: 2 + 14 + 3 + 4 = 23 → x.

Example 3
word="kiwi", size=1 → 'kiwi'
Constraints
  • 1 ≤ size ≤ 100
  • size ≤ len(word) ≤ 1000
  • len(word) is a multiple of size
  • word consists of lowercase English letters only
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsMultiplying Digit Strings MediumMultiply Complex Numbers in Strings MediumSeeded Playoff Bracket MediumTotal of a Fraction Chain MediumSolve for x Medium
loading Python…
Input
word="bcadzz", size=2
Expected
'ddy'

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