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 (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
🍳 The Fascinating Number RecipeBase Recipe (n)1923-digit starterDouble (2×n)384×2 = 384Triple (3×n)576×3 = 576🥘 Combined Recipe"192384576"All ingredients combined🔍 Quality Control Check❌ No ZerosForbidden ingredient✓ None found❌ No DuplicatesEach ingredient once✓ All unique✓ Complete SetAll digits 1-9✓ Perfect!🎉 FASCINATING NUMBER!
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!
Asked in
Google 15 Amazon 12 Meta 8 Microsoft 10
18.5K Views
Medium Frequency
~12 min Avg. Time
892 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen