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.
- Total pairs in an array such that the bitwise AND, bitwise OR and bitwise XOR of LSB is 1
- Calculate Bitwise OR of two integers from their given Bitwise AND and Bitwise XOR values
- Sum of Bitwise-OR of all subarrays of a given Array | Set 2
- Sum of bitwise AND of all subarrays
- Minimum possible Bitwise OR of all Bitwise AND of pairs generated from two given arrays
- Count distinct Bitwise OR of all Subarrays
- Maximize sum of squares of array elements possible by replacing pairs with their Bitwise AND and Bitwise OR
- Non-negative pairs with sum of Bitwise OR and Bitwise AND equal to N
- Leftover element after performing alternate Bitwise OR and Bitwise XOR operations on adjacent pairs
- Find subsequences with maximum Bitwise AND and Bitwise OR
- Count ways to generate pairs having Bitwise XOR and Bitwise AND equal to X and Y respectively
- Count pairs with bitwise XOR exceeding bitwise AND from a given array
- Count pairs with equal Bitwise AND and Bitwise OR value
- Number of subarrays have bitwise OR >= K
- Bitwise operations on Subarrays of size K
- Count even length subarrays having bitwise XOR equal to 0
- Differences between number of increasing subarrays and decreasing subarrays in k sized windows
- Sum of Bitwise And of all pairs in a given array
- Sum of bitwise OR of all possible subsets of given set
- 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 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.