VOOZH about

URL: https://www.geeksforgeeks.org/dsa/fascinating-number/

⇱ Fascinating Number - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Fascinating Number

Last Updated : 11 Jul, 2025

Given a number N, the task is to check whether it is fascinating or not. 
Fascinating Number: When a number( 3 digits or more ) is multiplied by 2 and 3, and when both these products are concatenated with the original number, then it results in all digits from 1 to 9 present exactly once. There could be any number of zeros and are ignored. 
Examples: 
 

Input: 192 
Output: Yes 
After multiplication with 2 and 3, and concatenating with original number, resultant number is 192384576 which contains all digits from 1 to 9.
Input: 853 
Output: No 
After multiplication with 2 and 3, and concatenating with original number, the resultant number is 85317062559. In this, number 4 is missing and the number 5 has appeared multiple times. 
 


 


Approach
 

  1. Check if the given number has three digits or more. If not, print No.
  2. Else, Multiply the given number with 2 and 3.
  3. Concatenate these products with the given number to form a string.
  4. Traverse this string, keep the frequency count of the digits.
  5. Print No if any digit is missing or has appeared multiple times.
  6. Else, print Yes.


Below is the implementation of above approach: 
 


Output: 
Yes

 

Time Complexity: O(|num|)

Auxiliary Space: O(10)

Comment