Maximize XOR-AND-XOR over Three Subsequences
Updated
Problem statement
You are given an array nums of non-negative integers. Partition its elements into three possibly empty subsequences A, B, and C. Every element must belong to exactly one subsequence.
For an empty subsequence, both its bitwise XOR and its bitwise AND are defined as 0. Return the maximum possible value of XOR(A) + AND(B) + XOR(C).
Function
maximumPartitionValue(nums: int[]) → longExamples
Example 1
nums = [1,2,3]return = 6Choose A = [1,2], B = [3], and C = []. The value is (1 XOR 2) + 3 + 0 = 6.
Example 2
nums = [7,7]return = 14Put one 7 in A and the other in B. This gives 7 + 7 + 0 = 14.
Example 3
nums = [5,1,9,3]return = 16One optimal partition is A = [5,1,9], B = [3], and C = []. Its value is 13 + 3 + 0 = 16.
Constraints
0 <= nums.length <= 15.0 <= nums[i] <= 1000000000.
More Google Onsite Interview questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Optimal Account BalancingAmazon · ONSITE INTERVIEW
- Hybrid Run-Length and Bit-Packing EncoderDatabricks · ONSITE INTERVIEWDatabricks interview questions
- Maximum XOR Between Two ArraysInMobi · ONSITE INTERVIEWInMobi interview questions
- Find the Two Unique NumbersZomato / Eternal · ONSITE INTERVIEWZomato / Eternal interview questions
- Find the Missing Number from 1 to nHyperVerge · ONSITE INTERVIEW
- Smallest Sufficient TeamExpedia · ONSITE INTERVIEWExpedia interview questions
- Missing and Repeated NumberCommvault · ONSITE INTERVIEWCommvault interview questions
- Check Endianness Of A Byte ArrayNVIDIA · ONSITE INTERVIEWNVIDIA interview questions
- Maximum Unique-Character Word SubsetMeta · ONSITE INTERVIEWMeta interview questions
- Largest Combination With Bitwise AND Greater Than ZeroMicrosoft · ONSITE INTERVIEWMicrosoft interview questions