FastPrepMaximize XOR-AND-XOR over Three Subsequences
Problems/Maximize XOR-AND-XOR over Three Subsequences

Maximize XOR-AND-XOR over Three Subsequences

Google logoGoogle● HardINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A firsthand Google Software Engineer intern report gives the full three-way XOR, AND, XOR goal and the rule for an empty subsequence. We rebuilt that values are non-negative, the input size limit, the function signature, and the return type. Our version is about 96% the same as the reported question.

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[]) → long

Examples

Example 1

nums = [1,2,3]return = 6

Choose A = [1,2], B = [3], and C = []. The value is (1 XOR 2) + 3 + 0 = 6.

Example 2

nums = [7,7]return = 14

Put one 7 in A and the other in B. This gives 7 + 7 + 0 = 14.

Example 3

nums = [5,1,9,3]return = 16

One 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

Interview reports that mention this question

  • Google SWE Intern OA and Interviews: 42 Experiences (Part 1 of 3)

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public long maximumPartitionValue(int[] nums) {
        // Write your code here.
    }
}
Checking account…