Maximize the sum of all prefix XORs

Revision en2, by karanarjunjr, 2022-08-28 08:08:13

You are given an array $$$A$$$ of $$$N$$$ positive integers and you are allowed to construct new array $$$B$$$ in the following manner: Traverse $$$A$$$ from left to right and for each $$$i$$$ you can put $$$A_i$$$ either to the left or right of $$$B$$$ ($$$B$$$ is initially empty). You need to maximize the sum of all prefix XORs of $$$B$$$, that is, maximize $$$(B_1) + (B_1 xor B_2) + (B_1 xor B_2 xor B_3)...$$$

This question was asked in an online assessment for which one of my friends appeared. Both of us weren't able to solve it. Can someone please help me out?

Tags xor, prefix, placement, help

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English karanarjunjr 2022-08-28 08:08:13 41
en1 English karanarjunjr 2022-08-28 07:57:15 562 Initial revision (published)