
You need to count occurrences at every place of the number.
You are given N = 13, then the number of occurrences of 3 in range [0, 13] = 2 (3, 13), you need to return 2.
The first line contains an integer ‘T’ which denotes the number of test cases or queries to be run. Then the test cases are as follows.
The first and only line of each test case contains a single integer ‘N’, denoting the higher limit of the range upto which you need to count the occurrences.
For each test case, print a single integer that denotes occurrences of 3.
Print the output of each test case in a separate line.
You don’t need to print anything; it has already been taken care of. Just implement the given function.
1 <= T <= 10^2
0 <= N <= 10^5
where ‘T’ is the number of test cases and 'N' is the given integer.
Time Limit: 1 sec
A basic approach will be to simply iterate through the range and keep a count of the occurrences of ‘3’ in each number of the range, and finally return it.
In this approach instead of traversing through the complete range, we will be creating cases for every digit of ‘N’. Using simple mathematics and observation we will try to come up with a method to count occurrences of ‘3’ in the range of [0, N], by just working with the digits of ‘N’.
Pair Product Div by K
Pair Product Div by K
Merge Two Sorted Arrays Without Extra Space
Merge Two Sorted Arrays Without Extra Space
Co-Prime
First Digit One
Special Digit Numbers