Count the Digits That Divide a Number - Problem
Given an integer num, return the number of digits in num that divide num.
An integer val divides nums if nums % val == 0.
Note: We cannot divide by zero, so digits equal to 0 should be ignored.
Input & Output
Example 1 — Basic Case
$
Input:
num = 121
›
Output:
2
💡 Note:
121 has digits 1, 2, 1. Digit 1 divides 121 (121/1 = 121), digit 2 does not divide 121 (121/2 = 60.5), digit 1 divides 121. So 2 digits divide 121.
Example 2 — All Digits Divide
$
Input:
num = 1248
›
Output:
4
💡 Note:
1248 has digits 1, 2, 4, 8. All digits divide 1248 evenly: 1248/1=1248, 1248/2=624, 1248/4=312, 1248/8=156. So all 4 digits divide the number.
Example 3 — Zero Digit
$
Input:
num = 1012
›
Output:
3
💡 Note:
1012 has digits 1, 0, 1, 2. We ignore 0 (can't divide by zero). Digits 1, 1, and 2 all divide 1012 evenly, so count is 3.
Constraints
- 1 ≤ num ≤ 109
- num does not contain 0 as a digit in most test cases
Visualization
Tap to expand
Understanding the Visualization
1
Input
Number 232 with digits 2, 3, 2
2
Process
Check each digit: 232%2=0✓, 232%3≠0✗, 232%2=0✓
3
Output
Count of 2 digits that divide evenly
Key Takeaway
🎯 Key Insight: Extract each digit and count how many divide the original number with zero remainder
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code