![]() |
VOOZH | about |
Given 4 integers A, B, Z1, and Z2. The task is to compare A*10Z1 and B*10Z2.
Examples:
Input: A = 19, Z1 = 2, B = 20, Z2 = 1
Output: A > B
Explanation:
A can be written as 1900
B can be written as 200
So, A is greater than B.Input:, A = 199, Z1 =10, B = 96, Z2 = 1000
Output: A < B
Explanation:
A can be written as 19900000....
B can be written as 9600000......
So, A is smaller than B
Naive Approach : Multiply A with Z1 zeroes and B with Z2 zeroes and compare both But large number cannot be store in long long integer more than 18 digits.
Time Complexity: O(1)
Auxiliary Space: O(1)
Efficient Approach: The idea is to compare the total number of digits in A and B because the largest digit number is maximum than the other.
Below is the implementation of the above approach.
A = B
Time Complexity: O(1)
Auxiliary Space: O(1)