Company: Rakuten
Difficulty: medium
Maximum possible score Problem Description Priya has an array A of size N , indexed from 1 to N , and has invented a game around it. A player picks an index K ( 1 ≤ K ≤ N ), which produces a second array B , also of size N , where each element is the bitwise XOR ( ^ ) of A_i and A_K , i.e. B_i = (A_i ^ A_K) . The player's score S is the sum of every element of B , that is S = ∑ i=1 N B i . Before letting anyone play, Priya wants to know the highest score any choice of K can produce. Examples Example 1: Input: N = 3, A = [15, 11, 8] Output: 11 Explanation: We need to pick an index K between 1 and N (here, 1 through 3 ) so that the sum of B_i = A_i ^ A_K is as large as possible. Picking K = 1 (so A_K = A_1 = 15 ): B_1 = A_1 ^ A_1 = 15 ^ 15 = 0 B_2 = A_2 ^ A_1 = 11 ^ 15 = 4 B_3 = A_3 ^ A_1 = 8 ^ 15 = 7 This gives score S = 0 + 4 + 7 = 11 . Picking K = 2 (so A_K = A_2 = 11 ): B_1 = A_1 ^ A_2 = 15 ^ 11 = 4 B_2 = A_2 ^ A_2 = 11 ^ 11 = 0 B_3 = A_3 ^ A_2 = 8 ^ 11 = 3 This gives score