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.
- 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
- Differences between number of increasing subarrays and decreasing subarrays in k sized windows
- Leftover element after performing alternate Bitwise OR and Bitwise XOR operations on adjacent pairs
- Find subsequences with maximum Bitwise AND and Bitwise OR
- Sum of XOR of all subarrays
- Sum of all Subarrays | Set 1
- Print all subarrays with 0 sum
- Number of subarrays having sum less than K
- Queries on XOR of XORs of all subarrays
- Count subarrays with Prime sum
- Sum of minimum elements 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 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.