1416. Restore The Array Hard

@problem@discussion
#String#Dynamic Programming



1/**
2 * [1416] Restore The Array
3 *
4 * A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits s and all we know is that all integers in the array were in the range [1, k] and there are no leading zeros in the array.
5 * Given the string s and the integer k, return the number of the possible arrays that can be printed as s using the mentioned program. Since the answer may be very large, return it modulo 10^9 + 7.
6 *  
7 * Example 1:
8 * 
9 * Input: s = "1000", k = 10000
10 * Output: 1
11 * Explanation: The only possible array is [1000]
12 * 
13 * Example 2:
14 * 
15 * Input: s = "1000", k = 10
16 * Output: 0
17 * Explanation: There cannot be an array that was printed this way and has all integer >= 1 and <= 10.
18 * 
19 * Example 3:
20 * 
21 * Input: s = "1317", k = 2000
22 * Output: 8
23 * Explanation: Possible arrays are [1317],[131,7],[13,17],[1,317],[13,1,7],[1,31,7],[1,3,17],[1,3,1,7]
24 * 
25 *  
26 * Constraints:
27 * 
28 * 	1 <= s.length <= 10^5
29 * 	s consists of only digits and does not contain leading zeros.
30 * 	1 <= k <= 10^9
31 * 
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/restore-the-array/
36// discuss: https://leetcode.com/problems/restore-the-array/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40impl Solution {
41    pub fn number_of_arrays(s: String, k: i32) -> i32 {
42        0
43    }
44}
45
46// submission codes end
47
48#[cfg(test)]
49mod tests {
50    use super::*;
51
52    #[test]
53    fn test_1416() {
54    }
55}
56


Back
© 2025 bowen.ge All Rights Reserved.