Maximum Product of Three Numbers

Given an integer array nums, find three numbers whose product is maximum and return the maximum product.

Example 1
Inputnums = [1,2,3]
Output6
The maximum product is obtained by multiplying 1, 2, and 3.
Example 2
Inputnums = [1,2,3,4]
Output24
The maximum product is obtained by multiplying 2, 3, and 4.

Constraints

  • 3 <= nums.length <= 10^4
  • -1000 <= nums[i] <= 1000

Asked at 15 companies

Practice questions like this out loud in a mock coding interview with a live AI interviewer. First one free.

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, what to keep, what's wrong, and the complexity of your solution.

Sign in to evaluate