Special Numbers

You are given an integer, ‘MAXVAL’. Your task is to determine the total number of special numbers present in the range, 1 to ‘MAXVAL’.

Note:
A special number is a number, which when rotated 180 degrees, resembles some other number in the same range. Every digit of a special number must be a valid digit.

The digits, 0,1,6,8,9, when rotated 180 degrees, become 0,1,9,8,6 respectively. While the digits, 2,3,4,5,7, when rotated do not become any valid digit.
For example:
‘8196’, when rotated 180 degrees, will become ‘9618’. We can observe that all the digits of this number are valid. So, this is a special number.
Input Format:
The first line contains an integer ‘T’, which denotes the number of test cases to be run. Then, the T test cases follow. 

The first line of each test case contains a single integer, ‘MAXVAL’.
Output Format:
For each test case, print a single integer, denoting the total number of special numbers in the range, 1 to ‘MAXVAL’.

Output for each test case will be printed in a separate line.
Note:
You do not need to print anything. It has already been taken care of. Just implement the given function.
Constraints:
1 <= T <= 10
1 <= MAXVAL < 10^4

Time Limit: 1sec
CodingNinjas
author
2y

Tip 1:
Tip 2:
Tip 3:

CodingNinjas
author
2y
Check all numbers independently

The approach is to loop through all the numbers in the given range one by one and check whether this number is a special number or not. We can check if a number is speci...read more

CodingNinjas
author
2y
Checking numbers having only special digits

The approach is to observe the fact that any special number will only have special digits in it. So, instead of checking all the numbers in the range, 1 to ‘...read more

Add answer anonymously...
Google Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter