You are given an integer array nums and an integer k. Consider every non-empty contiguous subarray of nums, and compute the bitwise OR of the elements in that subarray.
Return the k-th largest value among all subarray bitwise OR values. If the same OR value is produced by multiple subarrays, each occurrence is counted separately.
Examples
01 · Example 1
nums = [1, 2, 3] k = 5 return = 2
The subarray OR values are 1, 3, 3, 2, 3, 3. In descending order they are 3, 3, 3, 3, 2, 1, so the 5th largest value is 2.
02 · Example 2
nums = [5, 1] k = 2 return = 5
The OR values are 5, 5, and 1. The 2nd largest occurrence is still 5.
Constraints
1 <= nums.length <= 2 * 10^50 <= nums[i] < 2^311 <= k <= nums.length * (nums.length + 1) / 2
More Uber problems
- Total Palindrome Substring CostOA · Seen Jun 2026
- Earliest Time All Users Are ConnectedPHONE SCREEN · Seen May 2026
- Tournament Rounds by RankPHONE SCREEN · Seen May 2026
- Farthest Seat AssignmentONSITE INTERVIEW · Seen May 2026
- Convex Function MinimizationPHONE SCREEN · Seen May 2026
- Maximal Square AreaONSITE INTERVIEW · Seen May 2026
- First Unique IP Hitting the ServerPHONE SCREEN · Seen May 2026
- Jump Game with Prime-Step RuleOA · Seen May 2026
public int kthLargestSubarrayOr(int[] nums, long k) {
// write your code here
}nums[1, 2, 3]
k5
expected2
sign in to submit