LeetCode 898, Medium. Topics: Array, Dynamic Programming, Bit Manipulation. View on LeetCode.
Generate this problem as a practice environment: tested reference solution, 19 parametrized pytest cases, and a playground notebook:
Problem
Given an integer array arr, return the number of distinct bitwise ORs of all the non-empty subarrays of arr.
The bitwise OR of a subarray is the bitwise OR of each integer in the subarray. The bitwise OR of a subarray of one integer is that integer.
A subarray is a contiguous non-empty sequence of elements within an array.
Examples
Constraints
1 <= arr.length <= 5 * 10^4
0 <= arr[i] <= 10^9
Solution
Reference implementation from solution.py on GitHub, full suite in test_solution.py:
Complexity
Last modified on September 7, 2026