Give an array of positive integers, find the total sum after performing the bit wise OR operation on all the sub arrays of a given array.
Input : 1 2 3 4 5 Output : 71 Input : 6 5 4 3 2 Output : 84
First initialize the two variable sum=0, sum1=0, variable sum will store the total sum and, with sum1 we will perform bitwise OR operation for each jth element, and add sum1 with sum.
1:- Traverse the from 0th position to n-1.
2:- For each ith variable we will perform bit wise OR operation on all the sub arrays to find the total sum.
Repeat step until the whole array is traverse.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Sum of bitwise AND of all subarrays
- Sum of Bitwise-OR of all subarrays of a given Array | Set 2
- Number of subarrays have bitwise OR >= K
- Count distinct Bitwise OR of all Subarrays
- Total pairs in an array such that the bitwise AND, bitwise OR and bitwise XOR of LSB is 1
- Leftover element after performing alternate Bitwise OR and Bitwise XOR operations on adjacent pairs
- Differences between number of increasing subarrays and decreasing subarrays in k sized windows
- Find subsequences with maximum Bitwise AND and Bitwise OR
- Bitwise OR (or | ) of a range
- Bitwise Sieve
- Bitwise OR( | ) of all even number from 1 to N
- Bitwise AND of all the odd numbers from 1 to N
- Sum of bitwise AND of all submatrices
- Sum of Bitwise-OR of all Submatrices
- Bitwise AND of all even number up to N
- Bitwise and (or &) of a range
- Bitwise Operators in C/C++
- Sum of bitwise AND of all possible subsets of given set
- Sum of bitwise OR of all possible subsets of given set
- Sum of XOR of all subarrays
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.