Digit Inverse of a number is a number which can be found by replacing 0 with 9, 1 with 8, 2 with 7, 3 with 6, 4 with 5 and vice versa.
Can you find the digit inverse of the given number 'N'?
Example:Let 'N' = 1234567
Replacing 1 with 8, 2 with 7, 3 with 6, 4 with 5, 5 with 4, 6 with 3, 7 with 2. Thus the digit inverse of 'N' will be 8765432 as we replaced each digit in 'N'.
The first line of input contains an integer βTβ denoting the number of test cases.
The first line of each test case contains an integer βNβ representing the number whose digit inverse is to be found.
Output format :
For each test case, return an integer denoting the digit inverse of the given number.
Note :
You don't need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 10^5
0 <= N < 10^9
Time limit: 1 sec
2
9364
9999
635
0
In test case 1,
1. Replace 9 with 0
2. Replace 3 with 6
3. Replace 6 with 3
4. Replace 4 with 5
Thus the digit inverse of 9364 will be 635.
In test case 2,
1. Replace 9 with 0
2. Replace 9 with 0
3. Replace 9 with 0
4. Replace 9 with 0
Thus the digit inverse of 9999 will be 0.
2
426738
89347
573261
10652
706152
In test case 1,
1. Replace 4 with 5
2. Replace 2 with 7
3. Replace 6 with 3
4. Replace 7 with 2
5. Replace 3 with 6
6. Replace 8 with 1
Thus the digit inverse of 426738 will be 573261.
In test case 2,
1. Replace 8 with 1
2. Replace 9 with 0
3. Replace 3 with 6
4. Replace 4 with 5
5. Replace 7 with 2
Thus the digit inverse of 89347 will be 10652.
The approach is simple: just replace each digit with its inverse digit.
The approach is simple: just replace each digit with its inverse digit.
All we need to do is just traverse over each digit in the number and replace it with its digit inverse. We can get the last digit of a number by taking its modulo with 10 and then we will divide the number by 10 so that we can access the next digit. Simultaneously we will create a new number which is the digit inverse of the given number.
O(log10(N)), Where βNβ is the given number.
Since we will be traversing over each digit of the number. Thus the time complexity will be O(log10(N)).
O(1)
Since we are using constant extra space. Thus the space complexity will be O(1).