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-OR of all subarrays of a given Array | Set 2
- Number of subarrays have bitwise OR >= K
- Count distinct Bitwise OR of all Subarrays
- 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 all Subarrays | Set 1
- Number of subarrays having sum less than K
- Number of subarrays with odd sum
- Print all subarrays with 0 sum
- Count subarrays with same even and odd elements
- Generating subarrays using recursion
- Count subarrays with Prime sum
- Maximize the number of subarrays with XOR as zero
- Queries on XOR of XORs 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.