Check if The Number is Fascinating - Problem
The Fascinating Number Challenge
Have you ever wondered if a number has a magical property? In this problem, we explore the concept of fascinating numbers!
You are given a 3-digit integer n. A number is considered fascinating if, when you concatenate it with its double (
Example: If
•
•
•
• Concatenated:
• Contains digits 1,2,3,4,5,6,7,8,9 exactly once ✓
Goal: Return
Have you ever wondered if a number has a magical property? In this problem, we explore the concept of fascinating numbers!
You are given a 3-digit integer n. A number is considered fascinating if, when you concatenate it with its double (
2 × n) and triple (3 × n), the resulting string contains all digits from 1 to 9 exactly once and no zeros.Example: If
n = 192:•
n = 192•
2 × n = 384•
3 × n = 576• Concatenated:
"192384576"• Contains digits 1,2,3,4,5,6,7,8,9 exactly once ✓
Goal: Return
true if the number is fascinating, false otherwise. Input & Output
example_1.py — Basic Fascinating Number
$
Input:
n = 192
›
Output:
true
💡 Note:
192 → "192" + "384" + "576" = "192384576". This contains digits 1,2,3,4,5,6,7,8,9 exactly once each with no zeros, so it's fascinating.
example_2.py — Not Fascinating (Contains Zero)
$
Input:
n = 100
›
Output:
false
💡 Note:
100 → "100" + "200" + "300" = "100200300". This contains zeros and repeated digits, so it's not fascinating.
example_3.py — Not Fascinating (Missing Digits)
$
Input:
n = 183
›
Output:
false
💡 Note:
183 → "183" + "366" + "549" = "183366549". This contains repeated digit 3 and 6, missing digit 7, so it's not fascinating.
Constraints
- 100 ≤ n ≤ 999
- n consists of exactly 3 digits
- The concatenated result should be checked for digits 1 to 9 only
Visualization
Tap to expand
Understanding the Visualization
1
Prepare Ingredients
Calculate n, 2×n, 3×n and combine them
2
Quality Check
Ensure no forbidden ingredients (zeros) and no duplicates
3
Final Verification
Confirm we have exactly 9 unique ingredients (digits 1-9)
Key Takeaway
🎯 Key Insight: A fascinating number creates a perfect permutation of digits 1-9 when combined with its double and triple. Using a hash set allows us to validate this property efficiently in a single pass!
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code