Affluent Savvy
Photo by Julia Sakelli Pexels Logo Photo: Julia Sakelli

What is a mysterious number?

A mystery number is a number that can be expressed as the sum of two numbers and those two numbers should be the reverse of each other. Examples: Input : n = 121. Output : 29 92.

Why do I see colors during meditation?
Why do I see colors during meditation?

The body has energy centers, called chakras. Each of these is associated with a different color, and yogis believe that if you see a certain color...

Read More »
Which planet gives luxury?
Which planet gives luxury?

planet Venus As per Astrology, the planet Venus is considered the Lord of happiness and luxury. If the placement of planet Venus is good or in a...

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 »

Given a number, check whether it is a mystery number or not. A mystery number is a number that can be expressed as the sum of two numbers and those two numbers should be the reverse of each other.

Examples:

Input : n = 121

Output : 29 92 Input : n = 22

Output : 11 11

The idea is to try every possible pair smaller than or equal to n.

Below is the implementation of the above approach.

C++

#include using namespace std; int reverseNum( int x) { string s = to_string(x); reverse(s.begin(), s.end()); stringstream ss(s); int rev = 0; ss >> rev; return rev; } bool isMysteryNumber( int n) { for ( int i=1; i <= n/2; i++) { int j = reverseNum(i); if (i + j == n) { cout << i << " " << j; return true ; } } cout << "Not a Mystery Number" ; return false ; } int main() { int n = 121; isMysteryNumber(n); return 0; } Java class GFG { static int reverseNum( int x) { String s = Integer.toString(x); String str= "" ; for ( int i=s.length()- 1 ;i>= 0 ;i--) { str=str+s.charAt(i); } int rev=Integer.parseInt(str); return rev; } static boolean isMysteryNumber( int n) { for ( int i= 1 ; i <= n/ 2 ; i++) { int j = reverseNum(i); if (i + j == n) { System.out.println( i + " " + j); return true ; } } System.out.println( "Not a Mystery Number" ); return false ; } public static void main(String []args) { int n = 121 ; isMysteryNumber(n); } } Python3 def reverseNum(x): s = str (x) s = s[:: - 1 ] return int (s) def isMysteryNumber(n): for i in range ( 1 , n / / 2 + 1 ): j = reverseNum(i) if i + j = = n: print (i, j) return True print ( "Not a Mystery Number" ) return False n = 121 isMysteryNumber(n) C# using System; class GFG { static int reverseNum( int x) { string s = x.ToString(); string str= "" ; for ( int i=s.Length-1;i>=0;i--) { str=str+s[i]; } int rev=Int32.Parse(str); return rev; } static bool isMysteryNumber( int n) { for ( int i=1; i <= n/2; i++) { int j = reverseNum(i); if (i + j == n) { Console.WriteLine( i + " " + j); return true ; } } Console.WriteLine( "Not a Mystery Number" ); return false ; } public static void Main() { int n = 121; isMysteryNumber(n); } } PHP

How to earn $1,000 per day from home?
How to earn $1,000 per day from home?

List of Online Jobs without Investment Become a Subject Matter Expert. Chegg is a service provider to all students throughout the world. ......

Read More »
What do you say when someone dies unexpectedly?
What do you say when someone dies unexpectedly?

What to Say When Someone Dies Unexpectedly “I'm so sorry for your loss.” “Your loved one will be missed.” “If there's anything I can do to help,...

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 »

Javascript

Output: 29 92

Time Complexity: O(n)

Auxiliary Space: O(log 10 n)

Why do guys put a pillow under your hips?
Why do guys put a pillow under your hips?

Firstly, it can make vaginal and anal sex more pleasurable. By adding 'lift' to this part of the body, the angle at which penetration happens...

Read More »
Is it OK to pray for financial success?
Is it OK to pray for financial success?

Prayer to Give Finances Up to God Father, my finances belong to You. I thank You in advance for my financial prosperity. Lord, I know that...

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 does cinnamon do to cats?
What does cinnamon do to cats?

Cinnamon contains coumarin, a naturally occurring compound that's medically used as a blood thinner. "A large dose could conceivably cause problems...

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 »
Does luck exist in the world?
Does luck exist in the world?

Luck Does Exist The Cambridge English dictionary defines luck as 'the force that causes things, especially good things, to happen to you by chance...

Read More »