Company: MediaNet_july

Difficulty: medium

Problem Statement

Powerful Permutation Problem Description You are given an integer array A of length N. You may rearrange its elements into any permutation P of length N. Applying this permutation produces a new array Z - [A p0 , A p1 , ..., A pn ] From Z, build a power array X of size 20 as follows. X[i] = the largest j such that ∀ k ≤ j (Z[k] & 2 i ) ≠ 0, for 1 ≤ i ≤ 20 One power array F outranks another power array G whenever there is some index i with F[i] > G[i], while F[j] = G[j] holds for every j Determine the highest-ranked power array achievable across every possible permutation. Input Format The single argument is the integer array A. Output Format Return an integer array of size 20 holding the best power array obtainable. 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: One optimal ordering is [5, 4, 3, 2, 1]. Example 2: Input: A = [4, 16, 36, 30] Output: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,

More MediaNet_july OA questionsInterview experiences