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
Maximum Product of Three Numbers: [-4,-1,1,2,3]-4-1123Step 1: Identify key elementsTwo smallestLargest(-4) × (-1) × 3 = 12Output: 12
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
Asked in
Amazon 25 Microsoft 18 Apple 12
35.0K Views
Medium Frequency
~15 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