The Self Dividing Numbers interview question asks you to find all self-dividing numbers in a given range [left, right]. A self-dividing number is one that is divisible by every digit it contains. For example, 128 is self-dividing because 128 ÷ 1 = 128, 128 ÷ 2 = 64, and 128 ÷ 8 = 16 — all exact. A number containing the digit 0 is never self-dividing (division by zero is undefined).
Meta, Amazon, Google, and Epic Systems ask this beginner-level problem to test digit extraction, modulo arithmetic, and range iteration. It validates that candidates can cleanly check a per-digit property across all numbers in a range without over-engineering. It's also a good opportunity to demonstrate code clarity: a clean helper function is_self_dividing(n) followed by a list comprehension is the ideal solution.
The pattern is digit-by-digit validation with range filtering. For each number n in [left, right], extract its digits (using modulo and division). For each digit d, check that d != 0 and n % d == 0. If all digits pass, the number is self-dividing. Collect all such numbers. This is O((right - left) × log(right)) time — efficient for the constraints given.
Range: [1, 22].
Check 11: digits 1, 1. 11 % 1 = 0. ✓ Self-dividing. Check 12: digits 1, 2. 12 % 1 = 0, 12 % 2 = 0. ✓ Self-dividing. Check 13: digits 1, 3. 13 % 3 = 1 ≠ 0. ✗ Not self-dividing. Check 22: digits 2, 2. 22 % 2 = 0. ✓ Self-dividing.
Result: [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15, 22].
n % 0 causes a division by zero error; always check d != 0 first.int(c) — this works but mixing string/int operations is less elegant than pure digit extraction via modulo.n in-place during digit extraction — use a copy variable to extract digits while keeping the original n for divisibility checks.For the Self Dividing Numbers coding problem, the math interview pattern is a beginner-friendly digit extraction exercise. In Python, all(int(d) and n % int(d) == 0 for d in str(n)) captures the logic in a single line using string-based digit iteration. Google interviewers sometimes follow up: "Can you find the largest self-dividing number below 10 million?" — know that digit DP can count self-dividing numbers efficiently for very large ranges. Practice writing clean helper functions to keep the solution readable.