#2575
Find the Divisibility Array of a String
expert · 1060 · lc medium +32 · verified · 35.7% accepted · 587 likes · top 13%
Description
Given a digit string word and a positive integer m, build a divisibility array of the same length: each entry is 1 if the integer value of the prefix word[0..i] is divisible by m, and 0 otherwise. Return the divisibility array.
Example 1:
Input: word = "998244353", m = 3
Output: [1,1,0,0,0,1,1,0,0]
Explanation: There are only 4 prefixes that are divisible by 3: "9", "99", "998244", and "9982443".
Example 2:
Input: word = "1010", m = 10
Output: [0,1,0,1]
Explanation: There are only 2 prefixes that are divisible by 10: "10", and "1010".
Code
1
2
3