Given an array of positive integers. All numbers occur even number of times except one number which occurs odd number of times. Find the number in O(n) time & constant space.
Write a one line C function to return position of first 1 from right to left, in binary representation of an Integer. I/P 18, Binary Representation 010010 O/P 2 I/P 19, Binary Representation 010011 O/P 1
Given a positive integer, write a function to find if it is a power of two or not. Examples: Input : n = 4 Output : Yes 22 = 4 Input : n = 7 Output : No Input : n = 32 Output : Yes 25 = 32 We strongly recommend that you click… Read More »
We can multiply a number by 7 using bitwise operator. First left shift the number by 3 bits (you will get 8n) then subtract the original numberfrom the shifted number and return the difference (8n – n).
Parity: Parity of a number refers to whether it contains an odd or even number of 1-bits. The number has “odd parity”, if it contains odd number of 1-bits and is “even parity” if it contains even number of 1-bits. Main idea of the below solution is – Loop while n is not 0 and… Read More »
The very first solution that comes to our mind is the one that we learned in school. If sum of digits in a number is multiple of 3 then number is multiple of 3 e.g., for 612 sum of digits is 9 so it’s a multiple of 3. But this solution is not efficient.
Write a function that, for a given no n, finds a number p which is greater than or equal to n and is a power of 2.