Skip to content

Instantly share code, notes, and snippets.

@Obre
Created March 27, 2017 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Obre/ee5c5fa66a632dd906be297b8d0453dd to your computer and use it in GitHub Desktop.
Save Obre/ee5c5fa66a632dd906be297b8d0453dd to your computer and use it in GitHub Desktop.
function solution(N) {
if (N < 1) {
return 0;
}
var start = 0;
var gap = 0;
var count = 0;
for (i = 0; i < 31; i++) {
if (N & (1 << i)) {
start = i;
break;
}
}
for (i = start; i < 31; i++) {
if (N & (1 << i)) {
if (count > gap) {
gap = count;
}
count = 0;
} else {
count++;
}
}
return gap;
};
console.log(solution(1041));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment