Company: MediaNet_12sep
Difficulty: medium
Powerful Permutation Problem Description You are given an integer array A of length N. You can create any permutation P of length N. Using this permutation you can create an array Z, Z = [A P 0 , A P 1 , ..., A P N-1 ]. Now we will create a power array X of size 20 using this Z array. X[i] = maximum j such that v k <= j (Z[k] & 2 i-1 != 0) where 1 <= i <= 20 A power array F will be greater than a power array G if there exists an index i such that F[i] > G[i] given that v j < i, F[j] = G[j]. Find the largest possible power array for any permutation. Constraints 1 <= N <= 2 x 10 5 0 <= A[i] < 2 20 Examples Example 1: Input: A = [1, 2, 3, 4, 5] Output: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 1] Explanation: The optimal arrangement will be = [5, 4, 3, 2, 1] Example 2: Input: A = [4, 16, 16, 36, 36] Output: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 3, 0, 0] Explanation: The optimal arrangement will be = [36, 36, 4, 16, 16] You on