All problems
0719EasyMath

Crate Serial Checksum

Tracked in this browser only
Write code

Trains the technique from

LeetCode 1281Subtract the Product and Sum of Digits of an Integer

This 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.

Every crate leaving the yard is stamped with a serial number serial, a positive whole number written in base ten with no leading zeros.

The yard's clerk works out a checksum for the crate by multiplying all the decimal digits of serial together, adding all those same digits up, and then subtracting the second tally from the first.

Return the checksum. It may be negative.

Examples

Example 1

Input
serial = 705
Output
-12

The digits are 7, 0 and 5. Their product is 0 and their sum is 12, so the checksum is 0 - 12.

Example 2

Input
serial = 48
Output
20

The digits are 4 and 8. Their product is 32 and their sum is 12, so the checksum is 32 - 12.

Example 3

Input
serial = 9
Output
0

A one-digit serial has a product of 9 and a sum of 9, so the checksum is 9 - 9.

Constraints

  • 1 <= serial <= 10^5

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def digit_checksum(serial: int) -> int:
Java
public int digitChecksum(int serial)
September 7
Apply