All problems
0515EasyMathSorting

Two Wheels on the Dial

Tracked in this browser only
Write code

Trains the technique from

LeetCode 3536Maximum Product of Two Digits

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.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

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