Bit Manipulation

Total Hamming Distance

Problem Statement The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Now your job is to find the total Hamming distance between all pairs of the given numbers. Sample Test Cases Problem Solution  The fact that all numbers are represented using 32 bits (or some fixed number of …

Total Hamming Distance Read More »

Hamming Distance

Problem Statement The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Given two integers x and y, calculate the Hamming distance. Note:0 ≤ x, y < 231. Sample Test Cases Problem Solution 1)We find XOR of x and y , Why?Because the xor makes the bit to set if the bits bits are different ie, …

Hamming Distance Read More »

Find Missing Number In An Array Without Using Extra Space

Given an array of size n-1 which contains all the numbers within range 1 to n with exactly one number as missing. Find that missing number without using any extra space. Test Cases Test Case 1 Input: 1 2 4Output: 3Explanation: 3 is missing in the above array. Test Case 2 Input: 1 3 4 …

Find Missing Number In An Array Without Using Extra Space Read More »

Scroll to Top