- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Suppose we are given a range of integer numbers and are asked to find out the special numbers in the range. A special number is a number that is a positive integer having only 1 digit in its decimal representation. A number that has more than 1 digit in its decimal representation can also be special if the number is divisible by the count of digits in its decimal representation and the quotient value is itself a special number. We return the count of special numbers in the given range (left_limit, right_limit).

So, if the input is like left_limit = 5, right_limit = 30, then the output will be 13.

The special numbers in this range are: 5, 6, 7, 8, 9, 10, 12, 14, 16, 18, 20, 24, and 28.

To solve this, we will follow these steps −

- if right_limit < 10, then
- return right_limit - left_limit + 1

- len_right := size of string representation of (right_limit)
- number_list := [0,1,2,3,4,5,6,7,8,9,10,12,14,16,18]
- for j in range 2 to len_right + 1, do
- for each k in number_list, do
- temp1 := k * j
- if size of string representation of temp1 is same as j, then
- insert temp1 at the end of number_list

- otherwise when len(str(temp1)) > j, then
- come out from the loop

- if number_list[size of number_list - 1] >= right_limit, then
- come out from the loop

- for each k in number_list, do
- delete duplicate values from number_list and sort
- count := 0
- for each temp2 in number_list, do
- if temp2 >= left_limit and temp2 <= right_limit, then
- count := count + 1

- if temp2 >= left_limit and temp2 <= right_limit, then
- return count

Let us see the following implementation to get better understanding −

def strange(left_limit, right_limit): if right_limit < 10: return right_limit - left_limit + 1 len_right = len(str(right_limit)) number_list = [0,1,2,3,4,5,6,7,8,9,10,12,14,16,18] for j in range(2, len_right + 1): for k in number_list: temp1 = k*j if len(str(temp1)) == j: number_list.append(temp1) elif len(str(temp1)) > j: break if number_list[len(number_list)-1] >= right_limit: break number_list = list(set(number_list)) count = 0 for temp2 in number_list: if temp2 >= left_limit and temp2 <= right_limit: count = count + 1 return count print(strange(5, 30))

5, 30

13

- Related Questions & Answers
- Python Program to find out the determinant of a given special matrix
- Python - Find the number of prime numbers within a given range of numbers
- Program to find out special types of subgraphs in a given graph in Python
- Program to Find Out the Occurrence of a Digit from a Given Range in Python
- Program to find bitwise AND of range of numbers in given range in Python
- Program to Find Out the Special Nodes in a Tree in Python
- Program to find out number of distinct substrings in a given string in python
- Python Program to find out the number of sets greater than a given value
- Program to find out the value of a given equation in Python
- Python Program to Print all Numbers in a Range Divisible by a Given Number
- PHP program to find the sum of odd numbers within a given range
- Program to find count of numbers having odd number of divisors in given range in C++
- Program to find out the greatest subarray of a given length in python
- Write a Golang program to find prime numbers in a given range
- Program to find number of nodes in a range in Python

Advertisements