Created
September 28, 2018 04:40
-
-
Save RichardMarks/6da7905e27b75a787f8ed2c7cfd5aa39 to your computer and use it in GitHub Desktop.
Maximum Product of Two Positive Integers
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
const maxProduct = numbers => { | |
const count = numbers.length | |
let left = 0 | |
let right = 0 | |
for (let i = 0; i < count; i += 1) { | |
if (numbers[i] > left || numbers[i] > right) { | |
if (left < right) { | |
left = numbers[i] | |
} else { | |
right = numbers[i] | |
} | |
} | |
} | |
return left * right | |
} | |
export default maxProduct |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment