Tap here to switch tabs
Problem
Submissions

Problem: Concatenate Non-Zero Digits and Multiply by Sum II

Try to solve the Concatenate Non-Zero Digits and Multiply by Sum II problem.

Statement

You are given a string s consisting of digits and a 2D2 {D} integer array queries, where queries[i] = [l_i, r_i].

For each query:
11. Consider the substring of s from index l_i to index r_i inclusive.
22. Remove all occurrences of the digit ′0′'0' from this substring and concatenate the remaining digits in their original order to form an integer x. If there are no non-zero digits, x = 0.
33. Compute sum as the sum of all digits in x.
44. The answer for the query is (x×sum) mod (109+7)(x \times {sum}) \bmod (10^9 + 7).

Return an array of integers where the ii-th element is the answer to the ii-th query.

Constraints:

  • 1≤m==1 \leq m == s.length ≤105\leq 10^5

  • s consists of digits only.

  • 1≤1 \leq queries.length ≤105\leq 10^5

  • queries[i] =[li,ri]= [l_i, r_i]

  • 0≤li≤ri<m0 \leq l_i \leq r_i < m

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Concatenate Non-Zero Digits and Multiply by Sum II

Try to solve the Concatenate Non-Zero Digits and Multiply by Sum II problem.

Statement

You are given a string s consisting of digits and a 2D2 {D} integer array queries, where queries[i] = [l_i, r_i].

For each query:
11. Consider the substring of s from index l_i to index r_i inclusive.
22. Remove all occurrences of the digit ′0′'0' from this substring and concatenate the remaining digits in their original order to form an integer x. If there are no non-zero digits, x = 0.
33. Compute sum as the sum of all digits in x.
44. The answer for the query is (x×sum) mod (109+7)(x \times {sum}) \bmod (10^9 + 7).

Return an array of integers where the ii-th element is the answer to the ii-th query.

Constraints:

  • 1≤m==1 \leq m == s.length ≤105\leq 10^5

  • s consists of digits only.

  • 1≤1 \leq queries.length ≤105\leq 10^5

  • queries[i] =[li,ri]= [l_i, r_i]

  • 0≤li≤ri<m0 \leq l_i \leq r_i < m