
All numbers less than 30 with digits 2 and 5 are 2, 5, 22, 25.
The first line contains a single integer ‘T’ denoting the number of test cases to be run. Then the test cases follow.
The first line of each test case contains an integer N representing the number in the problem statement.
For each test case, print all the numbers less than N consisting of digits 2 and 5 only in a space-separated format. The numbers should be printed in ascending order.
Output for each test case will be printed in a separate line.
1 <= T <= 10
1 <= N <= 10^16
Time Limit: 1 sec
You are not required to print anything; it has already been taken care of. Just implement the function.
We can consider a number with digits 2 and 5 as a binary string where 0 represents a 2 in the number and 1 represents the 5. This way our total numbers consisting of 2 and 5 are limited by 2^(D + 1) where D is the total number of digits in the input number N.
So we define a recursive function that takes a current number of length D and either appends a 2 or 5 to the end of this number.
print(num, result) function takes the current number num and the result array ‘result’ and appends the numbers satisfying the above criteria to the result array.
Sorted Doubly Linked List to Balanced BST
Longest Substring with K-Repeating Characters
Expression Add Operators
Gray Code Transformation
Count of Subsequences with Given Sum