AlgoDaily

Max Product of Three Numbers

Read at your own pace. Code execution, quizzes, progress tracking, and the AI tutor are available in the interactive view with JavaScript enabled.

Description

Given an unsorted array of integers, can you write a method maxProductOfThree(unsorted: array) to find the largest product from three of the numbers? For example, given the following array:

[-1, 9, 22, 3, -15, -7]

The largest product of three numbers is 2310. This results from -15 * -7 * 22.

Constraints
  • Length of the array <= 100000
  • The array will contain values between -1000 and 1000
  • The final answer would always fit in the integer range
  • Expected time complexity : O(n * log n)
  • Expected space complexity : O(1)
```js
function maxProductOfThree(unsorted) {
	return unsorted;
}
```

CONTINUE WITH ALGODAILY PREMIUM

Keep going with the complete tutorial.

Unlock the remaining explanations and exercises, alongside the full learning library.

Explore Premium →
Open interactive view →