Created
July 4, 2022 00:38
-
-
Save allenhwkim/14dd1b705055797b2a62ac0dae231866 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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