• + 1 comment

    I was able to solve it using Python 3 after 7 attempts and got top 34% so I optimized it further using bit operator but same result, can anyone help me to optmized it further:

    Here is the code

    import os
    import sys
    
    MAX_EXP = 800
    
    def make_two_power_set():
        return {1 << i for i in range(MAX_EXP+1)}
    
    def count_matches(digits, powers):
        return sum(digits.count(str(power)) for power in powers)
    
    if __name__ == '__main__':
        two_power_set = make_two_power_set()
        fptr = open(os.environ['OUTPUT_PATH'], 'w')
    
        t = int(sys.stdin.readline().rstrip())
    
        for t_itr in range(t):
            a = sys.stdin.readline().rstrip()
    
            result = count_matches(a, two_power_set)
    
            fptr.write(str(result) + '\n')
    
        fptr.close()