FastPrepKth Largest Subarray Bitwise OR
Problems/Kth Largest Subarray Bitwise OR

Kth Largest Subarray Bitwise OR

Uber logoUberFULLTIMEOA

Updated Jul 2026

QuestionFunctionExamplesConstraints

Problem statement

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.

Function

kthLargestSubarrayOr(nums: int[], k: long) → int

Examples

Example 1

nums = [1, 2, 3]k = 5return = 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.

Example 2

nums = [5, 1]k = 2return = 5

The OR values are 5, 5, and 1. The 2nd largest occurrence is still 5.

Constraints

  • 1 <= nums.length <= 105
  • 0 <= nums[i] <= 109
  • 1 <= k <= nums.length * (nums.length + 1) / 2

More Uber Online Assessment questions

  • Count Palindromic Ancestor PathsOA · Seen Aug 2026
  • Jump Game with Prime-3 StepsOA · Seen Aug 2026
  • Last Truck to Leave the LaneOA · Seen Jul 2026
  • Chain of CommandOA · Seen Jul 2026
  • Total Palindrome Substring CostOA · Seen Jun 2026
  • Jump Game with Prime-Step RuleOA · Seen May 2026
  • Pipeline Throughput Maximization Under BudgetOA · Seen May 2026
  • Balanced Prefix Sets in a PermutationOA · Seen Apr 2026
  • Minimum Edge Reversals to Root a TreeOA · Seen Apr 2026
  • Maximum Riders in CarOA · Seen Apr 2026
All Uber interview questionsSee Uber hiring insights
Saved
class Solution {
    public int kthLargestSubarrayOr(int[] nums, long k) {
      // write your code here
    }
}
Checking account…