
Asked in CodeNation
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
4mo
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 Software Developer Intern Interview Questions Asked at CodeNation
Q. Rat in a Maze Problem Statement You need to determine all possible paths for a r...read more
Q. Graph Coloring Problem You are given a graph with 'N' vertices numbered from '1'...read more
Q. Minimum Fountains Activation Problem In this problem, you have a one-dimensional...read more
Interview Questions Asked to Software Developer Intern at Other Companies
Top Skill-Based Questions for CodeNation Software Developer Intern
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Operating Systems Interview Questions and Answers
250 Questions
System Design Interview Questions and Answers
250 Questions
C++ Interview Questions and Answers
150 Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

