Skip to main content
Back to problems
Leetcode
Medium
Arrays
Math
Simulation
Concatenate Non-Zero Digits and Multiply by Sum I

Build a number from the non-zero digits of an array, then multiply it by the sum of all digits in the array.

Acceptance 0%
Problem Statement

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 n integers nums[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

  • 1n1051 \le n \le 10^5
  • 0nums[i]90 \le nums[i] \le 9
  • All values in nums are single digits
Examples
Sample cases returned by the problem API.

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.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.