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.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Sum of bitwise AND of all subarrays
- Number of subarrays have bitwise OR >= K
- Sum of Bitwise-OR of all subarrays of a given Array | Set 2
- 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
- Sum of XOR of all subarrays
- Sum of all Subarrays | Set 1
- Sum of bitwise OR of all possible subsets of given set
- Bitwise AND of all the odd numbers from 1 to N
- Bitwise Sieve
- Bitwise OR( | ) of all even number from 1 to N
- Bitwise AND of all even number up to N
- Bitwise Operators in C/C++
- Bitwise and (or &) of a range
- Sum of bitwise AND of all submatrices
- Sum of Bitwise-OR of all Submatrices
- Sum of bitwise AND of all possible subsets of given set
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.