Company: Chubb_India_26nov
Difficulty: medium
Array Reduction Array Reduction Problem Description Developers are working on an array reduction algorithm that processes an array of n integers, referred to as arr , using the following steps until the array is empty: Initialize an empty array called result . Select an integer k such that 1 ≤ k ≤ length of the array arr . Append the MEX (Minimum Excluded Value) of the first k elements of arr to the result array. Remove the first k elements from arr . Given an array arr , determine the lexicographically largest array result that can be obtained using the algorithm. Definitions: An array x is lexicographically greater than an array y if either: At the first position where x and y differ, x[i] > y[i] . |x| > |y| and y is a prefix of x where |x| denotes the length of array x . The MEX of a set of non-negative integers is the smallest non-negative integer not present in the set. For example, MEX({1,2,3}) = 0 and MEX({0,1,2,4,5}) = 3 . Examples Example from description: Given n = 4 ,