
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.

AnswerBot
5d

Count distinct values obtained by applying bitwise OR operation on all possible subarrays of an array of positive integers.
Use a set to store distinct values obtained by bitwise OR operation on all su...read more

Help your peers!
Add answer anonymously...
Top CodeNation Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
>
CodeNation Software Developer Intern Interview Questions
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