Count the Digits That Divide a Number

Given an integer `num`, return the number of digits in `num` that divide `num`. A digit `d` divides `num` when `num % d == 0`. A digit that appears more than once is counted once per appearance.

30:00

Count the Digits That Divide a Number
easy
Free written solution
Topics
Companies

Given an integer num, return the number of digits in num that divide num.

A digit d divides num when num % d == 0. A digit that appears more than once is counted once per appearance.

Example 1:
Input: {"num":7}
Output: 1
Constraints:
  • 1≤num≤1091 \leq num \leq 10^9

  • num does not contain 0 as one of its digits.

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"num":7}

Start with count = 0 and a copy x = 7. We peel digits off x from the right and test each against the original num.

num = 7, peeled from the right

x 

7

✗

x = 7

d = x % 10, then test num % d

count

0

Variables
VariableValue
num7
x7
count0
DepthFunction Call
Stack empty
0/3