Skip to content

Instantly share code, notes, and snippets.

@allenhwkim
Created July 4, 2022 00:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save allenhwkim/14dd1b705055797b2a62ac0dae231866 to your computer and use it in GitHub Desktop.
Save allenhwkim/14dd1b705055797b2a62ac0dae231866 to your computer and use it in GitHub Desktop.
function solution(A) {
n = A.length;
maxProduct = Number.MIN_SAFE_INTEGER
A = A.sort( (a,b) => a-b) // <--- Important
maxProduct = Math.max(maxProduct, A[0] * A[1] * A[n-1]);
maxProduct = Math.max(maxProduct, A[n-3] * A[n-2] * A[n-1]);
return maxProduct;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment