Maximum Product of Two Digits - Problem

You are given a positive integer n. Return the maximum product of any two digits in n.

Note: You may use the same digit twice if it appears more than once in n.

Input & Output

Example 1 — Basic Case
$ Input: n = 253
Output: 25
💡 Note: The digits are 2, 5, and 3. The maximum product is 5 × 5 = 25 (using digit 5 twice)
Example 2 — Single Digit Repeated
$ Input: n = 99
Output: 81
💡 Note: The digits are 9 and 9. The maximum product is 9 × 9 = 81
Example 3 — Different Digits
$ Input: n = 1234
Output: 12
💡 Note: The digits are 1, 2, 3, and 4. The maximum product is 4 × 3 = 12

Constraints

  • 10 ≤ n ≤ 109
  • n is a positive integer

Visualization

Tap to expand
Maximum Product of Two DigitsInput253Extract Digits253Two largest5 × 5Output25
Understanding the Visualization
1
Input
Given integer n = 253
2
Process
Extract digits [2,5,3] and find two largest: 5 and 5
3
Output
Maximum product = 5 × 5 = 25
Key Takeaway
🎯 Key Insight: The maximum product always comes from multiplying the two largest digits in the number
Asked in
Google 25 Amazon 15 Facebook 12
25.0K Views
Medium Frequency
~10 min Avg. Time
890 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen