Company: MediaNet_23july
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 = [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 ∀ k <= j (Z[k] & 2 20-i != 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 ∀ j < i, F[j] = G[j]. Find the largest possible power array for any permutation. Constraints 1 <= N <= 2 * 10 5 0 <= A[i] < 2 20 Input Format The first argument is an integer array A. Output Format Return an integer array of size 20 which is the greatest power array that can be formed. Examples Example 1: Input1: A = [1, 2, 3, 4, 5] Output1: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 1] Example 2: Input2: B = [4, 16, 16, 36] Output2: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0