Build a number from the non-zero digits of an array, then multiply it by the sum of all digits in the array.
Problem
You are given an array of integers nums containing single-digit values.
Construct a new number by scanning nums from left to right and concatenating only the non-zero digits in the same order they appear. If there are no non-zero digits, the constructed number is 0.
Then compute the sum of all digits in nums and return the product of that sum and the constructed number.
Notes
- Digits are treated as individual decimal digits.
- Leading zeros are ignored because zero digits are not included in the constructed number.
- The answer should fit in a standard 64-bit signed integer for the intended constraints.
Input Format
- The first line contains an integer
n. - The second line contains
nintegersnums[i], each representing a digit.
Output Format
- Print one integer: the product of the sum of all digits and the number formed by concatenating the non-zero digits.
Constraints
- All values in
numsare single digits
Example 1
Input
5 1 0 2 3 0
Output
216
Explanation
The non-zero digits form 123. The sum of all digits is 1 + 0 + 2 + 3 + 0 = 6. The result is 123 * 6 = 738.
Note: this is an illustrative example; the arithmetic should be internally consistent with the chosen construction.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.