1410. Maximum Score from K Consecutive XOR Operations

HardBit ManipulationBit ManipulationSliding WindowXOR

Given an array of non-negative integers and a window size k, the score of a contiguous window of k elements is the XOR of those elements. Return the maximum score over all windows of exactly k consecutive elements.

Input: A JSON object {"nums": [<non-negative integers>], "k": <window size>} with 1 <= k <= len(nums).

Output: Return the maximum XOR over all length-k windows.

Examples

Example 1
Input: {"nums":[1,2,3,4,5],"k":2}
Output: 7
Explanation: The window [3,4] gives 3 XOR 4 = 7, the maximum.
Example 2
Input: {"nums":[5,5,5,5],"k":3}
Output: 5
Explanation: Every window XORs to 5.

Constraints

Asked by

AmazonGoogleMicrosoftMetaAdobe
Solve this problem in the editor →