Last active
June 19, 2023 11:28
-
-
Save julioflima/690f134e6d04a233245c26f505be45cb to your computer and use it in GitHub Desktop.
Google Step one
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 data = [50, 60, 40, 80, 30, 56, 63, 42, 65, 23]; | |
const findWidestInterval = (data) => { | |
if (Array.isArray(data) && !!data.length) { | |
const maxLostInterval = 0; | |
for (let i = 0; i < data.length - 1; i += 1) { | |
for (let j = i; j < data.length - 1; j += 1) { | |
const startPrice = data[i]; | |
const endPrice = data[j]; | |
const lost = startPrice-endPrice; | |
const interval = j-i; | |
if(lost < 0 && interval>maxLostInterval) maxLostInterval = interval | |
} | |
} | |
return maxLostInterval; | |
} | |
return 0; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment