Created
August 27, 2020 04:48
-
-
Save RomaSto/54ab79edfb8646652c33d81fcdb01b79 to your computer and use it in GitHub Desktop.
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
function solution(N) { | |
// write your code in JavaScript (Node.js 8.9.4) | |
if (N === parseInt(N, 10) && N >= 1 && N <= 2147483647) { | |
const binaryArray = N.toString(2).split(''); | |
let res = 0; | |
let acc = 0; | |
binaryArray.forEach((el, i, arr) => { | |
if (el === '0' && arr[i - 1] === '1') { | |
acc++; | |
} | |
else if (el === '0' && acc) { | |
acc++; | |
} | |
else if (el === '1') { | |
if (acc > res) { | |
res = acc; | |
} | |
acc = 0; | |
} | |
}); | |
return res; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment