## Number Complement Leetcode Solution

Problem Statement In this problem, we are given a decimal number. The goal is to find its complement. Example N = 15 0 N = 5 2 Approach (Flipping bit by bit) We can flip every bit in the integer ‘N’ to get its complement. The important part is, we …

## Hamming Distance Leetcode Solution

Problem Statement In this problem, we are given two integers, A and B, and the goal is to find the hamming distance between the given integers. The integers are greater that/equal to 0 and less than 231    Example First Integer = 5 , Second Integer = 2 3 First Integer …

## Number of Steps to Reduce a Number to Zero Leetcode Solution

The problem Number of Steps to Reduce a Number to Zero Leetcode Solution states that given an integer. Find the minimum number of steps to convert the given integer to 0. You can perform either of the two steps, either subtract 1 or divide the integer by 2. The problem …

## Convert a Number to Hexadecimal Leetcode Solution

The problem Convert a Number to Hexadecimal Leetcode Solution provides us with an integer. Then asks us to convert the given integer in decimal number system to hexadecimal number system. More formally, the question requires us to convert an integer given in base 10 to a base 16 representation. We …

## Power of Four Leetcode Solution

Problem Statement We are given an integer and we have to check if the number is power of 4 or not. A number is power of 4 if there exist an integer a such that,  num= 4^a. Example 16 true 5 false Approach 1 (Brute Force) An obvious way to …

## Power of Two Leetcode Solution

We are given an integer and the goal is to check whether the integer is a power of two, that is, it can be represented as some whole power of ‘2‘. Example 16 Yes 13 No Approach A trivial solution can be: Check if all prime factors of the integer …

## Sort Integers by The Number of 1 Bit Leetcode Solution

Problem statement In the problem ” Sort Integers by The Number of 1 Bit,” we are given an array arr. Our task is to sort the elements in the array according to the number of 1 bit in the binary representation of the number in ascending order. If two or …

## XOR Operation in an Array Leetcode Solution

Problem Statement In this problem we have to do XOR Operation in an Array of size n in which each element is equal to (start + 2*i) where i is the index of the element (0-indexed) and value of start is given. We have to return the bitwise XOR of …

## Subset Leetcode

In Subset Leetcode problem we have given a set of distinct integers, nums, print all subsets (the power set). Note: The solution set must not contain duplicate subsets. An array A is a subset of an array B if a can be obtained from B by deleting some (possibly, zero …

## Reverse Bits

Reverse bits of a given 32 bits unsigned integer. Example Input 43261596  (00000010100101000001111010011100) Output 964176192 (00111001011110000010100101000000) A 32-bit unsigned integer refers to a nonnegative number which can be represented with a string of 32 characters where each character can be either ‘0’ or ‘1’. Algorithm for i in range 0 …