Problems - Set 1
Easy
1. Addition of Two Numbers
public static int add(int a, int b) {
while (b != 0) {
int carry = a & b; // Calculate the carry by performing bitwise AND
a = a ^ b; // Perform bitwise XOR to add the numbers without carry
b = carry << 1; // Left shift the carry to perform addition with the next bit
}
return a;
}
public static void main(String[] args) {
int num1 = 2;
int num2 = 3;
int sum = add(num1, num2);
System.out.println("Sum of " + num1 + " and " + num2 + " is: " + sum);
}2. Swapping the 2 numbers

3. Convert Decimal to Binary Conversion
4. Check if a Number is Power of Two
5. Count the Number of Set Bits (Hamming Weight)
6. Find the Single Non-Repeating Element (XOR Trick)
7. Max Number among 2 Numbers
Medium
1. Reverse Bits of an Integer
2. Find the Missing Number
Difficult
Last updated