Skip to main content
Back to problems
Leetcode
Medium
Arrays
Math
Sorting
Amazon
Maximum Product Of Three Numbers

Find the maximum possible product of any three numbers in an integer array.

Acceptance 0%
Problem Statement

Given an integer array nums, choose any three distinct elements and multiply them together. Return the largest product you can make.

The key challenge is that negative numbers can change the result dramatically, so the optimal triple is not always the three largest values.

Input Format

  • An integer array nums with at least 3 elements.
  • Each element is an integer that may be negative, zero, or positive.

Output Format

  • Return a single integer: the maximum product obtainable from any three distinct elements in nums.

Constraints

  • 3 <= nums.length
  • Values may be negative, zero, or positive.
  • Use 64-bit arithmetic in reasoning if needed, since intermediate products may exceed 32-bit range.
Examples
Sample cases returned by the problem API.

Example 1

Input

nums = [1, 2, 3]

Output

6

Explanation

The only triple is 1 × 2 × 3 = 6.

Example 2

Input

nums = [1, 2, 3, 4]

Output

24

Explanation

The best choice is 2 × 3 × 4 = 24.

Show 1 more example

Example 3

Input

nums = [-10, -10, 5, 2]

Output

500

Explanation

Using the two negative numbers helps: (-10) × (-10) × 5 = 500.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.