The developers of Hackerland are working on an array reduction algorithm that takes in an array of n integers say arr and does the following until the array arr is empty:
Initialize an array result as an empty array
Choose an integer k such that k length of the array
Append the MEX of the first k elements of the array arr to the array result
Remove first k elements of the array arr
Given an array arr, find the lexicographically maximum array result that can be obtained using the above algorithm.
Note:
An array x is lexicographically greater than an array y if in the first position where x and y differ xi yi or if xy and y is a prefix of x where x denotes the size of the array x
The MEX of a set of nonnegative integers is the minimal nonnegative integer such that it is not in the set. For example, MEX and MEX
Example
Given n arr one of the optimal ways to make array result lexicographically maximum is as follows
Take k the MEX of the st and nd element of arr is So arr and result
Take k the MEX of the st and nd element of arr is So arr and result
arr is now empty and the answer is
Function Description
Complete the function getMaxArray in the editor below.
getMaxArray has the following parameter:
arrn: An array of integers
Returns
int: The lexicographically maximum array result that can be obtained using the above algorithm
Constraints
n means we need a solution with time complexity less than On
arri n