1397. Sum of XOR of All Subarrays

HardBit ManipulationBit MathPrefix XORCounting

Given an array of non-negative integers, compute the XOR of every contiguous subarray and return the sum of all these XOR values.

Input: A JSON object {"arr": [<non-negative integers>]}.

Output: Return the sum of the XOR over all subarrays.

Examples

Example 1
Input: {"arr":[1,3,5]}
Output: 24
Explanation: The six subarray XORs sum to 24.
Example 2
Input: {"arr":[9]}
Output: 9
Explanation: The only subarray XOR is 9.

Constraints

Asked by

AmazonGoogleMicrosoftMetaAdobe
Solve this problem in the editor →