Maximum Profit Under a Bitwise OR Limit
Updated
Problem statement
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) → longExamples
Example 1
values = [1,2,4]profits = [5,6,7]k = 3return = 11Select 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 = 21All 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 = 0Every nonempty subset has negative profit, so the empty subset is optimal.
Constraints
1 <= values.length == profits.length <= 20000 <= values[i] < 10240 <= 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