3756. Concatenate Non-Zero Digits and Multiply by Sum II Medium
1/**
2 * [3756] Concatenate Non-Zero Digits and Multiply by Sum II
3 *
4 * You are given a string s of length m consisting of digits. You are also given a 2D integer array queries, where queries[i] = [li, ri].
5 * For each queries[i], extract the <span data-keyword="substring-nonempty">substring</span> s[li..ri]. Then, perform the following:
6 *
7 * Form a new integer x by concatenating all the non-zero digits from the substring in their original order. If there are no non-zero digits, x = 0.
8 * Let sum be the sum of digits in x. The answer is x * sum.
9 *
10 * Return an array of integers answer where answer[i] is the answer to the i^th query.
11 * Since the answers may be very large, return them modulo 10^9 + 7.
12 *
13 * <strong class="example">Example 1:
14 * <div class="example-block">
15 * Input: <span class="example-io">s = "10203004", queries = [[0,7],[1,3],[4,6]]</span>
16 * Output: <span class="example-io">[12340, 4, 9]</span>
17 * Explanation:
18 *
19 * s[0..7] = "10203004"
20 *
21 * x = 1234
22 * sum = 1 + 2 + 3 + 4 = 10
23 * Therefore, answer is 1234 * 10 = 12340.
24 *
25 *
26 * s[1..3] = "020"
27 *
28 * x = 2
29 * sum = 2
30 * Therefore, the answer is 2 * 2 = 4.
31 *
32 *
33 * s[4..6] = "300"
34 *
35 * x = 3
36 * sum = 3
37 * Therefore, the answer is 3 * 3 = 9.
38 *
39 *
40 * </div>
41 * <strong class="example">Example 2:
42 * <div class="example-block">
43 * Input: <span class="example-io">s = "1000", queries = [[0,3],[1,1]]</span>
44 * Output: <span class="example-io">[1, 0]</span>
45 * Explanation:
46 *
47 * s[0..3] = "1000"
48 *
49 * x = 1
50 * sum = 1
51 * Therefore, the answer is 1 * 1 = 1.
52 *
53 *
54 * s[1..1] = "0"
55 *
56 * x = 0
57 * sum = 0
58 * Therefore, the answer is 0 * 0 = 0.
59 *
60 *
61 * </div>
62 * <strong class="example">Example 3:
63 * <div class="example-block">
64 * Input: <span class="example-io">s = "9876543210", queries = [[0,9]]</span>
65 * Output: <span class="example-io">[444444137]</span>
66 * Explanation:
67 *
68 * s[0..9] = "9876543210"
69 *
70 * x = 987654321
71 * sum = 9 + 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1 = 45
72 * Therefore, the answer is 987654321 * 45 = 44444444445.
73 * We return 44444444445 modulo (10^9 + 7) = 444444137.
74 *
75 *
76 * </div>
77 *
78 * Constraints:
79 *
80 * 1 <= m == s.length <= 10^5
81 * s consists of digits only.
82 * 1 <= queries.length <= 10^5
83 * queries[i] = [li, ri]
84 * 0 <= li <= ri < m
85 *
86 */
87pub struct Solution {}
88
89// problem: https://leetcode.com/problems/concatenate-non-zero-digits-and-multiply-by-sum-ii/
90// discuss: https://leetcode.com/problems/concatenate-non-zero-digits-and-multiply-by-sum-ii/discuss/?currentPage=1&orderBy=most_votes&query=
91
92// submission codes start here
93
94impl Solution {
95 pub fn sum_and_multiply(s: String, queries: Vec<Vec<i32>>) -> Vec<i32> {
96 vec![]
97 }
98}
99
100// submission codes end
101
102#[cfg(test)]
103mod tests {
104 use super::*;
105
106 #[test]
107 fn test_3756() {
108 }
109}
110Back
© 2026 bowen.ge All Rights Reserved.