Created
September 25, 2016 04:06
-
-
Save deadkff01/6f929d8b1300a00700889385959eb687 to your computer and use it in GitHub Desktop.
Stock Exchange Losses - Solution
This file contains hidden or 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
var n = parseInt(readline()); | |
var inputs = readline().split(' '); | |
var values = []; | |
for (var i = 0; i < n; i++) { | |
var v = parseInt(inputs[i]); | |
values.push(v); | |
} | |
maximal_loss = (values) => { | |
let subtractions = []; | |
values.reduce((prev, next) => { | |
subtractions.push((next - prev) < 0 ? next - prev : 0); | |
if (next < prev) | |
return prev; | |
return next; | |
}); | |
return Math.min(...subtractions); | |
} | |
print(maximal_loss(values)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment