Company: Amazon_28oct
Difficulty: medium
Lexicographically Maximum Array Result Problem Description A streaming service splits an incoming feed into consecutive segments. The feed is an array data_packets of n non-negative integers. The scheduler empties the feed by repeating the following step until no packet is left: pick an integer k with 1 <= k <= length(data_packets) ; compute the MEX of the first k packets, where the MEX of a collection of non-negative integers is the smallest non-negative integer that does not appear in it (MEX of {1, 2, 3} is 0 , MEX of {0, 1, 2, 4} is 3 ); append that MEX to an array result ; delete those first k packets from data_packets . Different choices of k give different arrays result . Report the lexicographically maximum result that the scheduler can produce. An array x is lexicographically greater than an array y if, at the first position where they differ, x holds the larger value, or if y is a proper prefix of x . For example [3, 2, 1] > [3, 1, 5] because 2 > 1 at position 1 ,