Trains the technique from
LeetCode 2950Number of Divisible SubstringsThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
Every lowercase letter carries a number. The first three letters carry 1, the next three carry 2, and so on in groups of three, so the last group, holding only y and z, carries 9.
A stretch of neighbouring letters is even-handed when the total of its letters' numbers divides exactly by how many letters the stretch holds.
Return how many even-handed stretches the word word holds.
Example 1
Each letter on its own is even-handed, and together they total 10 across two letters, which divides evenly.
Example 2
Every letter carries 9, so every stretch totals nine times its own length.
Example 3
The three single letters count, and so do the first two together totalling 2 and the last two totalling 10. All three together total 11, which three does not divide.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def count_divisible_substrings(word: str) -> int:public int countDivisibleSubstrings(String word)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.