Skip to content

Instantly share code, notes, and snippets.

@YanLobat
Last active September 24, 2016 13:56
Show Gist options
  • Save YanLobat/6ea19811e24f7912f713d55070fff8d6 to your computer and use it in GitHub Desktop.
Save YanLobat/6ea19811e24f7912f713d55070fff8d6 to your computer and use it in GitHub Desktop.
FloodDepth solution
function solution(A) {
let start = A[0];
let depth = 0;
let result = 0;
let min = 100000000;
for (let i = 1; i < A.length; i++) {
if (A[i] < start) {
if ((A[i] - min) > depth) {
depth = A[i] - min;
}
if (A[i] < min) {
min = A[i];
}
}
else {
depth = start - min;
if (result < depth) {
result = depth;
}
depth = 0;
min = 100000000;
start = A[i];
}
}
if ((!result) || (result < depth)) {
result = depth;
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment