Maximum and Minimum Product Triplets

Published by Helen Yu in

Write two functions:

  1. One that returns the maximum product of three numbers in an array.
  2. One that returns the minimum product of three numbers in an array.

Examples

maxProduct([-8, -9, 1, 2, 7]) ➞ 504

maxProduct([-8, 1, 2, 7, 9]) ➞ 126

minProduct([1, -1, 1, 1]) ➞ -1

minProduct([-5, -3, -1, 0, 4]) ➞ -15

Notes

N/A

Watch a quick demo on how Edabit works.