Dsa
Bit Manipulation
Easy
Mersenne Collector
In a stream of data, we are interested in 'Mersenne-style' integers: positive integers that consist entirely of 1s in their binary representation (e.g., 1, 3, 7, 15...). Given N integers, identify all such numbers and output their bitwise OR sum. If no such numbers exist, output 0.
Example:
Input:
4
3 10 7 8
Output:
7
Explanation:
3 is binary 11 (Valid). 10 is 1010 (Invalid). 7 is 111 (Valid). 8 is 1000 (Invalid). The OR sum of 3 and 7 is 7.
Key concepts
bitwise_orpowers_of_twovalidation
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now