ab | cde | fgh | ijk | lmn | opq | rst | uvw | xyz |
You are given a string text. Consider all of its non-empty contiguous pieces (equal pieces at different positions count separately). A piece is good if the total weight of its letters divides evenly by its length, that is, the average letter weight in the piece is a whole number.
Return the number of good pieces.text='bdh' → 4
Weights: b = 1, d = 2, h = 3. The single letters "b", "d", "h" qualify, and so does "bdh": sum 6, length 3, average 2. "bd" (3 / 2) and "dh" (5 / 2) have fractional averages. 4 in total.
text='az' → 3
a = 1, z = 9: the sum 10 divides by 2, so "a", "z" and "az" all qualify.
text='mop' → 4
text.length ≤ 2000text consists of lowercase English letterstext='bdh'
4
Run checks the first 3 tests in your browser. Submit checks all 93 tests on the server, hidden ones included.