We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Strange Counter
Strange Counter
+ 0 comments Simple Javascript Solution:
function strangeCounter(t) { let a = 3; let x = 1; let y = 3; while (y < t) { a = a * 2; x = y + 1; y = x + (a - 1); } return (a - (t-x)) }
+ 0 comments Java
public static long strangeCounter(long t) { long maxSize = 3; long count = 0; while (count<t){ count+=maxSize; maxSize*=2; } return (maxSize/2)-((maxSize/2)-((count-t)+1)); }
+ 0 comments start_value=3 ending_value =3 while ending_value <t: start_value *=2 ending_value +=start_value return ending_value-t+1
+ 0 comments Java
public static long strangeCounter(long t) { // Write your code here //3*2^0 + 3 * 2^1 + 3*2^n long x = 0L; long i = 0L; long s = 0L; long k = 1L; while(x < t){ x = (long)(3 * Math.pow(2,i)); k += x; if(k > t) { s = k - t; break; } i++; } return s; }
+ 0 comments PY
Simple code:
def strangeCounter(t): start_value = 3 while start_value - 2 <= t: start_value *= 2 return start_value - 2 - t
Load more conversations
Sort 865 Discussions, By:
Please Login in order to post a comment