All practice tasks

Coding (Algo)

Count Selections With a Target Mask

Backtracking · Medium

A bounded configuration exercise selects any subset of available mask toggles. Each toggle may be selected once, and two identical toggles still represent distinct choices. The tool needs the number of selections producing an exact final XOR mask.

Count index subsets whose combined XOR equals the target, including the empty selection when appropriate.

Input

Call

  • Implement solve(input) and return the result. The provided adapter handles JSON input and output.

Input shape

{ nums: unsigned32[], target: unsigned32 }

Fields

  • nums contains unsigned 32-bit integers from 0 through 4294967295. Values with bit 31 set are positive JSON integers.
  • target is an unsigned 32-bit integer from 0 through 4294967295.

Output

Return value

  • Return the number of subsets of indexes. Different index choices count separately even if values repeat.
  • The empty subset has XOR zero. With no inputs, return one for target zero and zero otherwise.

Constraints

  • 0 <= nums.length <= 20. The largest answer is 1048576.

Examples

Example 1

{
  "nums": [
    1,
    1
  ],
  "target": 0
}

Returns

2

Example 2

{
  "nums": [
    2147483648,
    0
  ],
  "target": 2147483648
}

Returns

2

Required complexity

O(2ⁿ) time and O(n) recursion space

What this task practices

Count Selections With a Target Mask is a coding (algo) interview exercise that trains prompt interpretation, explicit assumptions, a concrete response, and a clear explanation of tradeoffs. The catalog marks it as medium difficulty. It focuses on Technical Reasoning, Testing, Validation. The signed-in workspace provides the tools for the round and evaluates the attempt against task-specific criteria. Reference solutions, hidden checks, evaluator instructions, and candidate work remain private.

Sign in to startThe workspace and evaluation open after sign in.