• + 0 comments

    python solution

    def strangeCounter(t):
        # Write your code here
    
        #base case of t in bucket 0
        if t<=3:
            return 3-t+1
        
        #determine what bucket t is in
        floor=3
        ceiling=9
        bucket=0
        for n in range(1,1000000):
            if t>floor and t<=ceiling:
                bucket=n
                break
            else:
                floor=ceiling
                ceiling=3*2**(n+1)+floor
        return 3*2**bucket-(t-floor-1)