- Arrays, Bit Magic, Bitwise-AND, Bitwise-OR, Mathematical, subarray

Bitwise OR of Bitwise AND of all subarrays of an array

Bitwise OR of Bitwise AND of all subarrays of an arrayGiven an array arr[] consisting of N positive integers, the task is to find the Bitwise OR of Bitwise AND of all subarrays of the given array.Examples:Input: arr[] = {1, 2, 3}Output: 3Explanation:Following are the Bitwise AND of all possible subarrays are:{1}, Bitwise AND is 1.{1, 2}, Bitwise AND is 0.{1, 2, 3}, Bitwise AND is 0.{2}, Bitwise AND is 2.{2, 3}, Bitwise AND is 2.{3}, Bitwise AND is 3.The Bitwise OR of all the above values is 3.Input: arr[] = {1, 4, 2, 10}Output: 15Naive Approach: The simplest approach to solve the given problem is to generate all possible subarray of the given array and then find the Bitwise OR of all Bitwise AND of all the generated subarray as the result.Below is the implementation of the above approach:C++  #include using namespace std;  void findbitwiseOR(int* a, int n){        int res = 0;          for (int i = 0; i < n; i++) {                  int curr_sub_array = a[i];                  res = res | curr_sub_array;          for (int j = i; j < n; j++) {                          curr_sub_array = curr_sub_array                             & a[j];            res = res | curr_sub_array;        }    }          cout