1327. Count Subsets with Given XOR

MediumBit ManipulationBitmaskXORDynamic Programming

Given an array of non-negative integers and a target k, count how many subsets have a XOR equal to k. The empty subset is included and has XOR 0.

Input: A JSON object {"nums": [<non-negative integers>], "k": <target>}.

Output: Return the number of subsets whose XOR equals k.

Examples

Example 1
Input: {"nums":[6,9,4,2],"k":6}
Output: 2
Explanation: Two subsets XOR to 6.
Example 2
Input: {"nums":[1,1],"k":0}
Output: 2
Explanation: The empty subset and {1,1} both XOR to 0 -> 2.

Constraints

Asked by

AmazonMicrosoftGoogleAdobeFlipkart
Solve this problem in the editor →