Sort by

recency

|

1002 Discussions

|

  • + 0 comments

    Here is my c++ solution, you can watch the explanation here : https://youtu.be/Plsx1i8dqiI

    long strangeCounter(long t) {
        long last = 3, step = 3;
        while(t > last){
            step *= 2;
            last += step;
        }
        return last - t + 1;
    }
    
  • + 0 comments

    Python without loop

    def strangeCounter(t):
        # Write your code here
        r = math.ceil(math.log2(t/3+1)) # Calculate the number of current round
        sum_full = 3*(2**r-1) # Calculate the time when value reach to 1 at current round
        return sum_full - t + 1
    
  • + 0 comments

    long strangeCounter(long t) { long b = 1, tmp = 3, idx = 3, j; while (idx < t){ b += tmp; tmp *= 2; idx += tmp; } j = t - b + 1; return tmp - j + 1; }

  • + 0 comments

    def strangeCounter(t):! start=1 end=3 no = 3 ans=0 while(endend): break start = start+no no = no*2 end = end+no ans = 1+(end-t) return ans

  • + 0 comments

    return 6 * (2 ** math.floor(math.log2(1 + (t - 1) / 3))) - 2 - t