Ctrl K

Digit Windows That Divide

Easy
You get integers number and width. Write number in decimal and look at every contiguous piece of that notation that is exactly width digits long. Each piece is read as a number; leading zeros are fine ("07" means 7). Count how many pieces divide number evenly. A piece equal to zero never counts as a divisor. Equal pieces at different positions are counted separately.
Example 1
number=1236, width=2 → 1

The windows are 12, 23 and 36. 1236 is divisible by 12 (103 · 12) but not by 23 or 36, so the answer is 1.

Example 2
number=5005, width=2 → 1

The windows are 50, 00 and 05. 5005 is not divisible by 50, 00 is zero and is never a divisor, while 05 = 5 divides 5005. The answer is 1.

Example 3
number=777, width=1 → 3
Constraints
  • 1 ≤ number ≤ 10¹⁸
  • 1 ≤ width ≤ the number of digits in number
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsValue of a Roman Numeral EasySum of Binary Strings EasySpreadsheet Column Label EasySpreadsheet Column Index EasyCounting Off by Threes and Fives Easy
loading Python…
Input
number=1236, width=2
Expected
1

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