Show problems as
Classic problem #3536EasyMathSorting

Maximum Product of Two Digits

Real-world version: Two Wheels on the Dial
Tracked in this browser only
Read Maximum Product of Two Digits on LeetCode(opens in a new tab)

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

Python
def largest_dial_product(reading: int) -> int:
Java
public int largestDialProduct(int reading)