2575. Find the Divisibility Array of a String Medium

@problem@discussion
#Array#Math#String



1/**
2 * [2575] Find the Divisibility Array of a String
3 *
4 * You are given a 0-indexed string word of length n consisting of digits, and a positive integer m.
5 * The divisibility array div of word is an integer array of length n such that:
6 * 
7 * 	div[i] = 1 if the numeric value of word[0,...,i] is divisible by m, or
8 * 	div[i] = 0 otherwise.
9 * 
10 * Return the divisibility array of word.
11 *  
12 * <strong class="example">Example 1:
13 * 
14 * Input: word = "998244353", m = 3
15 * Output: [1,1,0,0,0,1,1,0,0]
16 * Explanation: There are only 4 prefixes that are divisible by 3: "9", "99", "998244", and "9982443".
17 * 
18 * <strong class="example">Example 2:
19 * 
20 * Input: word = "1010", m = 10
21 * Output: [0,1,0,1]
22 * Explanation: There are only 2 prefixes that are divisible by 10: "10", and "1010".
23 * 
24 *  
25 * Constraints:
26 * 
27 * 	1 <= n <= 10^5
28 * 	<font face="monospace">word.length == n</font>
29 * 	<font face="monospace">word</font><font face="monospace"> consists of digits from 0 to 9</font>
30 * 	<font face="monospace">1 <= m <= 10^9</font>
31 * 
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/find-the-divisibility-array-of-a-string/
36// discuss: https://leetcode.com/problems/find-the-divisibility-array-of-a-string/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40impl Solution {
41    pub fn divisibility_array(word: String, m: i32) -> Vec<i32> {
42        vec![]
43    }
44}
45
46// submission codes end
47
48#[cfg(test)]
49mod tests {
50    use super::*;
51
52    #[test]
53    fn test_2575() {
54    }
55}
56


Back
© 2025 bowen.ge All Rights Reserved.