SHARE
TWEET

Untitled

a guest Sep 16th, 2019 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solution(N) {
  2.  
  3.   Numb = String(N.toString(2));
  4.   N = 0;
  5.   var m1 = Numb.indexOf('1', 0);
  6.   var count = 0;
  7.   var pos = Numb.indexOf('1');
  8.   var m2 = 0;
  9.  
  10.   while (pos !== -1) {
  11.     count++;
  12.     pos = Numb.indexOf('1', pos + 1);
  13.   }
  14.  
  15.   for (var i = 0; i < count; i++) {
  16.     m2 = Numb.indexOf('1', +m1 + 1);
  17.     N = Math.max((m2 - m1), N);
  18.     m1 = m2;
  19.   }
  20.  
  21.   if (N == 0) {
  22.     N = 1;
  23.   }
  24.  
  25.   return N - 1;
  26. }
  27.  
  28. var Numb = Number(prompt("Input N:"));
  29. console.log(Numb);
  30. console.log(Numb.toString(2));
  31. console.log(solution(Numb));
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top