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:
result as an empty arrayk such that 1 ≤ k ≤ length of the arrayk elements of the array arr to the array resultk elements of the array arr
Given an array arr, find the lexicographically maximum array result that can be obtained using the above algorithm.
Note:
x is lexicographically greater than an array y if in the first position where x and y differ xi > yi or if |x| > |y| and y is a prefix of x (where |x| denotes the size of the array x).Examples
01 · Example 1
arr = [0,1,1,0] return = [2,2]
Given Take
Take
n = 4, arr = [0,1,1,0], one of the optimal ways to make array result lexicographically maximum is as follows -
k = 2, the MEX of the 1st and 2nd element of arr is 2. So arr = [1,0] and result = [2].k = 2, the MEX of the 1st and 2nd element of arr is 2. So arr = [] and result = [2,2].arr is now empty and the answer is [2,2].Constraints
More Snowflake problems
- Effective Role PrivilegesPHONE SCREEN · Seen May 2026
- Closest Bathroom / Desk on a GridPHONE SCREEN · Seen May 2026
- Minimum Clicks Between Wiki PagesOA · Seen May 2026
- Minimum Index Distance Between Person and CakeOA · Seen May 2026
- Simple Array Rotation GameSeen Apr 2026
- Max Element Indexes After RotationsOA · Seen Mar 2026
- String Formation (Also for AI/ML Software Engineer Intern :)OA · Seen Mar 2026
- Grid Traversal (Infrastructure Automation Internship)Seen May 2025
public int[] arrayReductionAlgorithm(int[] arr) {
// write your code here
}
arr[0,1,1,0]
expected[2,2]
sign in to submit