Find the largest product obtainable by choosing any two digits from a number.
Problem
Given a non-negative integer, consider the decimal digits that appear in it. Your task is to choose two different digits from the number and return the maximum possible product of those two digits.
If the number has fewer than two digits, the problem is not well-defined for forming a pair. In practice, such cases should be handled safely by returning 0.
Because only the digits matter, the order in which they appear does not affect the product.
Goal
Compute the largest product of any two digits in the input number.
Input Format
- A single non-negative integer
n. - You may treat the value as a string of decimal digits or as an integer whose digits are to be examined.
Output Format
- Return a single integer: the maximum product of any two distinct digits in
n.
Constraints
0 <= n- Digits are decimal digits in the range
0to9. - If fewer than two digits are available, return
0.
Example 1
Input
n = 2736
Output
18
Explanation
The digits are 2, 7, 3, and 6. The largest product comes from 6 × 3 = 18.
Example 2
Input
n = 909
Output
81
Explanation
The digits are 9, 0, and 9. The best pair is 9 × 9 = 81.
Show 1 more example
Example 3
Input
n = 7
Output
0
Explanation
There is only one digit, so no pair can be formed. Returning 0 is the safest convention.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.