Trains the technique from
LeetCode 3754Concatenate Non-Zero Digits and Multiply by Sum IThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A water meter prints a whole-number reading n. The billing system turns that reading into a single audit figure from two ingredients.
n from left to right, throw away every digit equal to 0, and read whatever digits are left as a decimal number, keeping their original order. When nothing is left, the trimmed reading is 0.n.Return the trimmed reading multiplied by the digit total. The product can be larger than a signed 32-bit integer holds.
Example 1
Dropping the single `0` leaves the digits `5`, `8`, `3`, `6`, so the trimmed reading is 58306 without its zero, namely 5836. The digit total is 5 + 8 + 3 + 0 + 6 = 22, and 5836 * 22 = 128392.
Example 2
The trimmed reading is 497 and the digit total is 4 + 9 + 0 + 7 = 20, so the answer is 497 * 20 = 9940.
Example 3
No digit is thrown away, so the trimmed reading equals the reading itself. The digit total is 9 + 1 = 10, and 91 * 10 = 910.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def sum_and_multiply(n: int) -> int:public long sumAndMultiply(int n)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.