Input: A[] = {4, 5, 2, 25, 10, 5, 10, 3, 10, 5}
Output: 5, 10, 10, -1, -1, 10, -1, 5, -1, -1
Explanation:
A[0] (= 4): Array elements greater than 4 are {5, 25, 10}. Since 5 occurs maximum number of times, set B[0] = 5.
A[1] (= 5): Array elements greater than 5 are {25, 10}. Since 10 occurs maximum number of times, set B[1] = 10.
A[2] (= 2): Array elements greater than 2 are {5, 25, 10}. Since 10 occurs maximum number of times, set B[2] = 10.
A[3] (= 25): No element greater than A[3] found on its right. Therefore, set B[3] = -1.
A[4] (= 10): No element greater than A[4] found on its right. Therefore, set B[4] = -1.
Similarly, set B[5] = 10, B[6] = -1, B[7] = 5, B[8] = -1, B[9] = -1.
Therefore, the obtained array is B[] = {5, 10, 10, -1, -1, 10, -1, 5, -1, -1}.
Input: A[] = {1, 1, 3, 3, 2, 2}
Output: 2, 2, -1, -1, -1, -1