Self Dividing Numbers - Problem
A self-dividing number is a number that is divisible by every digit it contains.
For example, 128 is a self-dividing number because:
128 % 1 == 0128 % 2 == 0128 % 8 == 0
A self-dividing number is not allowed to contain the digit zero.
Given two integers left and right, return a list of all the self-dividing numbers in the range [left, right] (both inclusive).
Input & Output
Example 1 — Basic Range
$
Input:
left = 1, right = 22
›
Output:
[1,2,3,4,5,6,7,8,9,11,12,15,22]
💡 Note:
Numbers like 10, 20 contain zero (invalid). 13: 13%3=1≠0 (invalid). 22: 22%2=0 ✓ (valid)
Example 2 — Three-Digit Numbers
$
Input:
left = 47, right = 85
›
Output:
[48,55,66,77]
💡 Note:
48: 48%4=0, 48%8=0 ✓. 55: 55%5=0 ✓. 66: 66%6=0 ✓. 77: 77%7=0 ✓
Example 3 — Single Number Range
$
Input:
left = 128, right = 128
›
Output:
[128]
💡 Note:
128: 128%1=0, 128%2=0, 128%8=0, all digits divide evenly
Constraints
- 1 ≤ left ≤ right ≤ 104
Visualization
Tap to expand
Understanding the Visualization
1
Input Range
Given range [left, right] to search
2
Check Each Number
Test divisibility by each digit
3
Collect Valid Numbers
Return list of self-dividing numbers
Key Takeaway
🎯 Key Insight: Numbers with zero digits are automatically invalid due to division by zero
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code