Skip to main content
Back to problems
#2729
Easy Algorithms

Check if the number is fascinating

Hash Table Math
52.9% acceptance
Feb 25, 2026
263
14
You are given an integer n that consists of exactly 3 digits. We call the number n fascinating if, after the following modification, the resulting number contains all the digits from 1 to 9 exactly once and does not contain any 0's: Concatenate n with the numbers 2 * n and 3 * n. Return true if n is fascinating, or false otherwise.

Solution

Rust
Time O(n)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn is_fascinating(n: i32) -> bool {
    let s = format!("{}{}{}", n, 2 * n, 3 * n);
    if s.len() != 9 { return false; }
    let mut counts = [0u8; 10];
    for b in s.bytes() { counts[(b - b'0') as usize] += 1; }
    counts[0] == 0 && counts[1..].iter().all(|&c| c == 1)
  }
}