Trains the technique from
LeetCode 1281Subtract the Product and Sum of Digits of an IntegerThis 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.
Example 1
The digits are 7, 0 and 5. Their product is 0 and their sum is 12, so the checksum is 0 - 12.
Example 2
The digits are 4 and 8. Their product is 32 and their sum is 12, so the checksum is 32 - 12.
Example 3
A one-digit serial has a product of 9 and a sum of 9, so the checksum is 9 - 9.
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 digit_checksum(serial: int) -> int:public int digitChecksum(int serial)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.