Skip to content

Instantly share code, notes, and snippets.

@deadkff01
Created September 25, 2016 04:06
Show Gist options
  • Save deadkff01/6f929d8b1300a00700889385959eb687 to your computer and use it in GitHub Desktop.
Save deadkff01/6f929d8b1300a00700889385959eb687 to your computer and use it in GitHub Desktop.
Stock Exchange Losses - Solution
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