FastPrepMaximum Profit Under a Bitwise OR Limit
Problems/Maximum Profit Under a Bitwise OR Limit

Maximum Profit Under a Bitwise OR Limit

Concentric AI logoConcentric AI● MediumFULLTIMEOA

Updated Aug 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The original report specifies choosing a subset whose bitwise OR is at most a limit and maximizing corresponding profit. It does not define the empty subset or portable bounds. This practice version permits the empty subset and uses a ten-bit OR domain for exact dynamic programming.

You are given equal-length arrays values and profits, and a nonnegative integer k.

Select any subset of indices. The subset is feasible when the bitwise OR of its selected values[i] is at most k. Its profit is the sum of its selected profits[i].

Return the maximum profit of a feasible subset. The empty subset is allowed, has bitwise OR 0, and has profit 0.

Function

maxProfitUnderOrLimit(values: int[], profits: int[], k: int) → long

Examples

Example 1

values = [1,2,4]profits = [5,6,7]k = 3return = 11

Select the first two items. Their OR is 3 and their total profit is 11. Selecting the third item would make the OR exceed the limit.

Example 2

values = [3,5,6]profits = [4,10,7]k = 7return = 21

All three items can be selected. Their OR is 7 and their total profit is 21.

Example 3

values = [1,2]profits = [-5,-1]k = 3return = 0

Every nonempty subset has negative profit, so the empty subset is optimal.

Constraints

  • 1 <= values.length == profits.length <= 2000
  • 0 <= values[i] < 1024
  • 0 <= k < 1024
  • -1000000 <= profits[i] <= 1000000
  • The answer fits in a signed 64-bit integer.

More Concentric AI interview questions

  • Kth Greater Element Index to the RightOA · Seen Sep 2026
  • Find the Intersection Node of Two Linked ListsOA · Seen Sep 2026
  • Count Students Outside Their Sorted PositionsOA · Seen Aug 2026
  • Minimum Weighted Manhattan Travel CostOA · Seen Aug 2026
  • Rearrange a Linked List from Alternating EndsONSITE INTERVIEW · Seen Sep 2026

Similar questions at other companies

  • Count Routes Through Four Shop TypesOpenAI · OAOpenAI interview questions
  • Vehicle Builds for Required Terrain (Game Adaptation)Roblox · OARoblox interview questions
  • Minimum Moves to Spread Stones Across a GridAmerican Express · OAAmerican Express interview questions
  • Bitwise XOR SubsequencesJP Morgan Chase · OAJP Morgan Chase interview questions
  • Beautiful Number OrderingsDocuSign · OADocuSign interview questions
  • Paint a Grid with Three ColorsIntuit · OAIntuit interview questions
  • Minimum Operations To Reduce To ZeroUber · OAUber interview questions
  • Bitwise XOR SubsequencesGoldman Sachs · OAGoldman Sachs interview questions
  • Delete K Subsets for Maximum ScoreRubrik · OARubrik interview questions
  • Optimize Discount Selection Under a Point BudgetPalantir · OAPalantir interview questions
All Concentric AI interview questionsSee Concentric AI hiring insights
Saved
class Solution {
    public long maxProfitUnderOrLimit(int[] values, int[] profits, int k) {
        // Write your code here.
    }
}
Checking account…