Affluent Savvy
Photo by Shamia Casiano Pexels Logo Photo: Shamia Casiano

What is a fantastic number?

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.

What to do with $30,000?
What to do with $30,000?

The Best Ways To Invest $30K Right Now Stocks & ETFs. Unsurprisingly, one of the best ways to invest $30,000 is to invest in a variety of stocks...

Read More »
What is the magic golden herb?
What is the magic golden herb?

Turmeric, also known as the “Golden Spice of India” is a root that is easily identified by its golden colour. It is a warm and slightly bitter...

Read More »

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:

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

Below is the implementation of above approach:

C++14

#include using namespace std; bool isFascinating( int num) { int freq[10] = {0}; string val = "" + to_string(num) + to_string(num * 2) + to_string(num * 3); for ( int i = 0; i < val.length(); i++) { int digit = val[i] - '0' ; if (freq[digit] and digit != 0 > 0) return false ; else freq[digit]++; } for ( int i = 1; i < 10; i++) { if (freq[i] == 0) return false ; } return true ; } int main() { int num = 192; if (num < 100) cout << "No" << endl; else { bool ans = isFascinating(num); if (ans) cout << "Yes" ; else cout << "No" ; } } Java import java.io.*; import java.util.*; public class GFG { public static boolean isFascinating( int num) { int [] freq = new int [ 10 ]; String val = "" + num + num * 2 + num * 3 ; for ( int i = 0 ; i < val.length(); i++) { int digit = val.charAt(i) - '0' ; if (freq[digit]> 0 && digit != 0 ) return false ; else freq[digit]++; } for ( int i = 1 ; i < freq.length; i++) { if (freq[i] == 0 ) return false ; } return true ; } public static void main(String args[]) { int num = 192 ; if (num < 100 ) System.out.println( "No" ); else { boolean ans = isFascinating(num); if (ans) System.out.println( "Yes" ); else System.out.println( "No" ); } } } Python 3

What are the top 3 trending hashtags?
What are the top 3 trending hashtags?

Currently, the 100 most popular Instagram hashtags are as follows: #love. #instagood. #photooftheday. #fashion. #trending. #explorepage. #viral....

Read More »
Can we put broom under bed?
Can we put broom under bed?

There are many disadvantages of keeping a broom under the bed. By doing this for a regular time, financial constraints remain in the house....

Read More »
Awaken your dormant DNA ability to attract wealth effortlessly
Awaken your dormant DNA ability to attract wealth effortlessly

The simple yet scientifically proven Wealth DNA method laid out in the report allows you to effortlessly start attracting the wealth and abundance you deserve.

Learn More »

def isFascinating(num) : freq = [ 0 ] * 10 val = ( str (num) + str (num * 2 ) + str (num * 3 )) for i in range ( len (val)) : digit = int (val[i]) if freq[digit] and digit ! = 0 > 0 : return False else : freq[digit] + = 1 for i in range ( 1 , 10 ) : if freq[i] = = 0 : return False return True if __name__ = = "__main__" : num = 192 if num < 100 : print ( "No" ) else : ans = isFascinating(num) if ans : print ( "Yes" ) else : print ( "No" ) C# using System; class GFG { public static bool isFascinating( int num) { int [] freq = new int [10]; String val = "" + num.ToString() + (num * 2).ToString() + (num * 3).ToString(); for ( int i = 0; i < val.Length; i++) { int digit = val[i] - '0' ; if (freq[digit] && digit != 0 > 0 ) return false ; else freq[digit]++; } for ( int i = 1; i < freq.Length; i++) { if (freq[i] == 0) return false ; } return true ; } static void Main() { int num = 192; if (num < 100) Console.WriteLine( "No" ); else { bool ans = isFascinating(num); if (ans) Console.WriteLine( "Yes" ); else Console.WriteLine( "No" ); } } } PHP 0 && $digit != 0) return false; else $freq [ $digit ]++; } for ( $i = 1; $i < 10; $i ++) { if ( $freq [ $i ] == 0) return false; } return true; } $num = 192; if ( $num < 100) echo "No" ; else { $ans = isFascinating( $num ); if ( $ans ) echo "Yes" ; else echo "No" ; } ?> Javascript

What is the newest side hustle?
What is the newest side hustle?

50+ Best Side Hustle Ideas For 2022: Legit Ways To Earn Extra... Start a blog. List your unused space online. Offer social media management...

Read More »
How do you tell if the Universe is telling you something?
How do you tell if the Universe is telling you something?

How to Recognize Signs From the Universe Cultivate the Desire to Receive. This is a valuable yet often overlooked starting point for any kind of...

Read More »

Output: Yes

Time Complexity: O(|num|)

Auxiliary Space: O(10)

Do red lights calm you down?
Do red lights calm you down?

Red light therapy devices emit a light with a wavelength of 650 to 700 nanometers. This light has a calming effect on the body, which is why it's...

Read More »
Why are I am affirmations so powerful?
Why are I am affirmations so powerful?

"I am" affirmations are also powerful because these are true intentions that you want to have in your life. You say these words because you care...

Read More »
Awaken your dormant DNA ability to attract wealth effortlessly
Awaken your dormant DNA ability to attract wealth effortlessly

The simple yet scientifically proven Wealth DNA method laid out in the report allows you to effortlessly start attracting the wealth and abundance you deserve.

Learn More »
What are my dreams trying to tell me?
What are my dreams trying to tell me?

“Dreams are often about identity, because we're figuring out who we are and what we need, and the beliefs and perspectives we hold,” says Wallace....

Read More »
Awaken your dormant DNA ability to attract wealth effortlessly
Awaken your dormant DNA ability to attract wealth effortlessly

The simple yet scientifically proven Wealth DNA method laid out in the report allows you to effortlessly start attracting the wealth and abundance you deserve.

Learn More »
What manna looks like?
What manna looks like?

Manna is described as white and comparable to hoarfrost in colour. According to the book of Exodus, manna is like a coriander seed in size but is...

Read More »