## Find two duplicate elements in an limited range array (using XOR)

Given an array of integers with all its elements between 1 to n with the exception of two elements which occur twice. Find two duplicate elements without using any extra memory.

Coding made easy

Given an array of integers with all its elements between 1 to n with the exception of two elements which occur twice. Find two duplicate elements without using any extra memory.

Given a positive number N, efficiently generate binary numbers between 1 to N using queue data structure and in linear time.

Given an limited range array of integers of size n with all its elements between 1 to n with the exception of one element which occur twice and one number which is missing from the list. Find missing number and the duplicate element in linear time and without using any extra memory. For example, …

Given an integer, swap consecutive b bits starting from given positions in binary representation of the integer. The bits to be swapped should not overlap with each other.

Given a number n, find previous power of 2. If n itself is a power of 2, return n.

Given a number n, find next highest power of 2. If n itself is a power of 2, return n.

Given two 16-bit positive values stored in 32-bit integer variables, find the product using the 8-bit multiply operator that that takes two 8-bit numbers and returns a 16-bit value.

Given two integers, find their minimum and maximum without using branching.

Given an integer, count set bits in it.

In this post, we will see how to compute parity of a number using lookup table. The parity refers to the number of 1’s in a given binary number. Odd parity (encoded as 1) means there are an odd number of 1’s and even parity (encoded as 0) means that there are an even …

Given an integer, count its set bits.

In this post, we will see how to conditionally negate a value without branching. The expression ((flag^(flag-1))*n) negate n when the flag is false and the expression ((n^-flag)+flag) negate n when the flag is true. How does it work? 1. For (flag ^ (flag – 1)) * n if flag = 0, …