Maximum Product of Two Digits

You are given a positive integer `n`. Return the maximum product of any two digits of `n`. **Note:** the same digit value may be used twice if it appears more than once in `n`.

30:00

Maximum Product of Two Digits
easy
Free written solution
Topics
Companies

You are given a positive integer n.

Return the maximum product of any two digits of n.

Note: the same digit value may be used twice if it appears more than once in n.

Example 1:
Input: {"n":31}
Output: 3
Constraints:
  • 10≤n≤10910 \leq n \leq 10^9

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"n":31}

Two empty seats: a holds the largest digit, b the second largest. Both start at 0, and we read the digits of 31 from the right.

n = 31, digits read from the right

3

1

0

b

0

a

a x b = 0 x 0 = 0

Variables
VariableValue
n31
a0
b0
DepthFunction Call
Stack empty
0/5