
Please assume that there is at least one valid solution.
The first line contains an integer ‘T’ denoting the number of test cases. Then each test case follows.
The first input line of each test case contains an integer ‘N’.
For each test case, the output will be “1” if you have returned the correct answer, else it will be “0”.
The output of each test case will be printed in a separate line.
Note: You are not required to print the expected output; it has already been taken care of. Just implement the function.
1 <= T <= 50
1 <= N <= 10000
Where ‘T’ is the number of test cases, ‘N’ is the given number.
Time limit: 1 sec
The basic idea of this approach is to consider every possible pair [A, B] such that A + B == ‘N’ and check if both ‘A’ and ‘B’ do not contain 0 as a digit.
Let us try to implement a function withoutZero(int n) which takes a positive integer ‘n’ and returns true if it doesn’t contain any 0 in its decimal representation otherwise returns false.
The idea here is to go through each digit of its decimal representation and check if it is zero or not.
Now, consider the following steps to implement withoutZero(int n).
Consider the following steps to find the valid pair [A, B].
The basic idea of this approach is to start building two non-zero numbers from the least significant digit. Let's say we get a digit ‘x’ such that 2 <= ‘x’ <= 9 in the ‘N’. We can simply have 1 and ‘x’ - 1 as a digit in ‘A’ and ‘B’ respectively. The only problem arises when ‘x’ is either 0 or 1. We can handle this case separately. For ‘x’ == 1, we can have 2 and 9 as a digit in ‘A’ and ‘B’ respectively. For ‘x’ == 0, we have 1 and 9 as a digit in ‘A’ and ‘B’ respectively.
Consider the following steps: