Count Distinct Bitwise OR of All Subarrays
Given an array of positive integers, determine the number of distinct values obtained by applying the bitwise OR operation on all possible subarrays.
Explanation:
A subarray is a contiguous portion of the array that maintains the original order of elements. The bitwise OR operation combines two numbers at the bit level, outputting a 1 in each bit position where at least one of the corresponding bits is 1.
Input:
The first line contains an integer T
, the number of test cases. For each test case, the first line contains an integer N
, the size of the array. The second line contains N
space-separated integers, representing the elements of the array.
Output:
For each test case, output a single integer representing the count of distinct values obtainable as the result of bitwise OR on all subarrays of the given array.
Example:
Input:2
3
1 2 3
4
1 1 2 3
Output:6
5
Constraints:
1 <= T <= 100
1 <= N <= 3000
1 <= ARR[i] <= 10^9
- Time Limit: 1 second
Note:
The implementation should focus on computing the count efficiently without printing anything, as the I/O is handled automatically.
Be the first one to answer
Add answer anonymously...
Top Google Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
Top HR questions asked in Google Software Developer Intern
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app