Skip to content

Instantly share code, notes, and snippets.

@f3ath
Last active January 23, 2017 05:29
Show Gist options
  • Save f3ath/2b65501687187ab78f73a6485127429b to your computer and use it in GitHub Desktop.
Save f3ath/2b65501687187ab78f73a6485127429b to your computer and use it in GitHub Desktop.
function longest_ones_sequence(m) {
for (
var r = m.length - 1, c = m[0].length - 1;
r >= 0 && c >= 0;
m[r][c] === '1' ? c-- : r--
);
return m[0].length - c - 1;
}
console.log(
longest_ones_sequence(
[
"0 0 1 1 1 1 1 1",
"0 0 0 0 0 0 0 0",
"0 1 1 1 1 1 1 1",
"0 0 0 0 0 0 1 1",
"0 0 1 1 1 1 1 1"
].map(function (s) {
return s.split(' ')
})
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment