• + 0 comments

    A number is only divisible by 3 if the sum of its digits is divisible by 3.

    So make a loop to sum the digits into a variable. You'll only need to check if that one number is divisible by 3. If yes, then any combination of its digits will be divisible by 3.

    def canConstruct(a): digits_sum = 0 for i in a: str_i = str(i) for x in str_i: digits_sum += int(x)