math and geometry January 1, 2023

Count the digits that divide a number

Time O(n) Space O(1) Open original problem

We will iterate over each digit and check if it is a divisor of the number. If it is, we will increment the counter.

class Solution:
    def countDigits(self, num: int) -> int:
        return sum(num % int(n) == 0 for n in str(num))

Time complexity: O(n)
Space complexity: O(1)