Maximum Product of Three Numbers - Problem
Given an integer array nums, find three numbers whose product is maximum and return the maximum product.
Note: The solution is guaranteed to fit in a 32-bit integer.
Input & Output
Example 1 — Basic Case
$
Input:
nums = [1,2,3]
›
Output:
6
💡 Note:
Only one triplet possible: 1 × 2 × 3 = 6
Example 2 — Negative Numbers
$
Input:
nums = [1,2,3,4]
›
Output:
24
💡 Note:
Maximum product from three largest: 2 × 3 × 4 = 24
Example 3 — Mixed Signs
$
Input:
nums = [-1,-2,-3]
›
Output:
-6
💡 Note:
All negative numbers: (-1) × (-2) × (-3) = -6
Constraints
- 3 ≤ nums.length ≤ 104
- -1000 ≤ nums[i] ≤ 1000
Visualization
Tap to expand
Understanding the Visualization
1
Input Array
Given integer array with positive and negative values
2
Find Extremes
Identify largest and smallest values efficiently
3
Compare Products
Calculate and compare key combinations
Key Takeaway
🎯 Key Insight: Two negative numbers multiply to positive, potentially creating larger products than three positives
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code