less than 1 minute read

Given a list of integers nums, find the largest product of three distinct elements.

Constraints

  • 3 ≤ n ≤ 100,000 where n is the length of nums

https://binarysearch.com/problems/Max-Product-of-Three-Numbers

Examples

Example 1

Input

  • nums = [5, 4, 1, 3, -2, -2]

Output

  • answer = 60

Explanation

We can multiply 5 * 4 * 3

Example 2

Input

  • nums = [-3, 1, 1, 0]

Output

  • answer = 0

Explanation

We can multiply 1 * 1 * 0

Solution

Leave a comment