Skip to content

Instantly share code, notes, and snippets.

@RichardMarks
Created September 28, 2018 04:40
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 RichardMarks/6da7905e27b75a787f8ed2c7cfd5aa39 to your computer and use it in GitHub Desktop.
Save RichardMarks/6da7905e27b75a787f8ed2c7cfd5aa39 to your computer and use it in GitHub Desktop.
Maximum Product of Two Positive Integers
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