Question bank › Bit Manipulation
Dsa Bit Manipulation Medium

Bitwise AND Sum

Given a list of integers, write a program that calculates the sum of all distinct values produced by the bitwise AND operation on all pairs of integers from the list. Input format: - The first line contains an integer N (1 <= N <= 1000), the size of the list. - The second line contains N space-separated integers (0 <= A[i] <= 10^4). Output format: - Output a single integer representing the sum of the distinct AND values. Example: Input: 4 2 3 5 7 Output: 8 (AND pairs: 2&3, 2&5, 2&7, 3&5, etc. resulting in distinct values: 0, 2, 3, 5, 6, 7 which sum to 8)

Key concepts

bit_manipulationsums

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
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.