Dsa
Bit Manipulation
Easy
Bitwise OR Sum
You are given an array of n integers. Write a program that computes the sum of bitwise OR values for all pairs (i, j) where 0 <= i < j < n. Output the sum.
Input:
First line contains an integer n (1 <= n <= 1000).
Second line contains n space-separated integers (0 <= arr[i] <= 10^6).
Output:
The sum of bitwise OR values of all unique pairs.
Example:
Input:
3
1 2 3
Output:
9
Explanation:
Pairs are (1,2), (1,3), and (2,3). Bitwise OR of these pairs are 3, 3, 3 respectively. Total sum is 9.
Key concepts
bit_manipulationmath
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