Maximum Product of Two Digits
Real-world version: Two Wheels on the DialThe statement here is our own: the same inputs, outputs and technique.
A mechanical counter shows the value reading on a row of digit wheels, one wheel per decimal digit, with no leading wheel showing a zero.
An inspector picks two different wheels and multiplies the two digits they show. Two wheels showing the same digit are still two different wheels, so a repeated digit may be used twice as long as it comes from two separate wheels.
Return the largest product the inspector can obtain.
Examples
Example 1
- Input
- reading = 7744
- Output
- 49
The wheels show 7, 7, 4 and 4. The two wheels showing 7 are different wheels, so their digits multiply to 49.
Example 2
- Input
- reading = 45067
- Output
- 42
The wheels show 4, 5, 0, 6 and 7, and the wheels showing 7 and 6 multiply to 42.
Example 3
- Input
- reading = 8069
- Output
- 72
The wheels show 8, 0, 6 and 9, and the wheels showing 9 and 8 multiply to 72.
Constraints
- 10 <= reading <= 10^9
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def largest_dial_product(reading: int) -> int:public int largestDialProduct(int reading)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 12 test cases: 12 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's