Maximum Product of Two Digits - Problem
Given a positive integer n, you need to find the maximum product of any two digits within that number.
๐ฏ Goal: Extract all individual digits from the number and find the pair that gives the highest product when multiplied together.
Important: You can use the same digit twice if it appears multiple times in the number. For example, in the number 323, you can multiply the digit 3 by itself since it appears twice.
Example: For n = 3726, the digits are [3, 7, 2, 6]. The maximum product would be 7 ร 6 = 42.
Input & Output
example_1.py โ Basic Case
$
Input:
n = 3726
โบ
Output:
42
๐ก Note:
The digits are [3, 7, 2, 6]. The largest two digits are 7 and 6, so 7 ร 6 = 42 is the maximum product.
example_2.py โ Repeated Digits
$
Input:
n = 9911
โบ
Output:
81
๐ก Note:
The digits are [9, 9, 1, 1]. The largest digit 9 appears twice, so 9 ร 9 = 81 is the maximum product.
example_3.py โ Two Digit Number
$
Input:
n = 23
โบ
Output:
6
๐ก Note:
The digits are [2, 3]. Since we only have two digits, the product is 2 ร 3 = 6.
Constraints
- 1 โค n โค 109
- n is a positive integer
- The number will have at least 2 digits
Visualization
Tap to expand
Understanding the Visualization
1
Extract All Digits
Break down the number into individual digits
2
Identify Largest Two
Find the two highest valued digits
3
Calculate Product
Multiply these two digits for maximum result
Key Takeaway
๐ฏ Key Insight: The maximum product of any two digits always comes from multiplying the two largest digits in the number - no need to check all combinations!
๐ก
Explanation
AI Ready
๐ก Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code