Ninja want to add coding to his skill set so he started learning it. On the first day, he stuck to a problem in which he has given a long integer āXā and had to count the number of digits in it.
Ninja called you for help as you are his only friend. Help him to solve the problem.
EXAMPLE:Input: 'X' = 2
Output: 1
As only one digit is ā2ā present in āXā so answer is ā1ā.
The first line will contain the integer 'T', denoting the number of test cases.
Each test case contains a single long integer āXā.
Output format :
For each test case, print the number of digits in the given integer āXā.
Note :
You don't need to print anything. It has already been taken care of. Just implement the given function.
1 <= 'T' <= 1000
1 <= āXā <= 10^18
Time Limit: 1 sec
2
89
870
2
3
In test case ā1ā. There are ā2ā digits present in ā89ā that is ā8ā and ā9ā. So the answer is ā2ā.
In test case ā2ā. There are ā3ā digits present in ā870ā that is ā8ā, ā7ā and ā0ā. So the answer is ā3ā.
2
240
1
3
1
How many times we can remove one digit from it?
Approach:
We will remove the least significant digit from the given integer by dividing it by 10 until the number does not become zero. The number of times we can perform the above operation is the answer.
Algorithm :
O(log10(X)). Where āXā is the input long integer.
As we are deleting ā1ā digit every time when we enter in the while loop. So ānumber of digitsā will be the time complexity that will be O(log10(X)).
O(1).
As we are maintaining a constant variable to store the answer, the space complexity will be O(1).