View on GitHub

leetcode-diaries

A journal to record the solution of the various Leetcode problems solved over the course of time.

Maximum Product of Three Numbers

Leetcode problem 628; Difficulty: Easy

Problem Statement

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

Constraints:

Example 1:

Input: nums = [1,2,3]

Output: 6

Example 2:

Input: nums = [1,2,3,4]

Output: 24

Example 3:

Input: nums = [-1,-2,-3,-4]

Output: -6

Example 4:

Input: nums = [-1,-2,-3,4]

Output: 24

Example 5:

Input: nums = [-1,-2,-3, 2, 4, 5]

Output: 40

Submitted Solution

The implemented solution received the following rating on Leetcode:

image