![]() |
VOOZH | about |
Given two numbers, the task is to check if two numbers are equal without using Arithmetic and Comparison Operators or String functions.
Method 1 : The idea is to use XOR operator. XOR of two numbers is 0 if the numbers are the same, otherwise non-zero.
Not Same
Time Complexity: O(1)
Auxiliary Space: O(1)
Method 2 : Here idea is using complement ( ~ ) and bit-wise '&' operator.
Not Same
Time Complexity: O(1)
Auxiliary Space: O(1)
Approach:
Another approach is to use bit manipulation to compare each bit of the two numbers. We can use the bit-shift operators to extract each bit and compare them one by one.
True False
Time complexity: O(log n)
Space complexity: O(1)
Source: https://www.geeksforgeeks.org/dsa/count-of-n-digit-numbers-whose-sum-of-digits-equals-to-given-sum/