This is a verified interview question from De-shaw. Candidates reporting seeing this problem in recent Online Assessments (OAs) and onsite rounds. Mastering "Minimum Moves to Non-Increasing Array" covers key patterns like Arrays.
"A company is organizing a batch process, where each batch consists of several task groups arranged in a line and numbered from left to right. Each group currently has a certain number of tasks assigned, represented by the array tasks, where tasks[i] is the number of tasks in the ith group. To optimize the process, the company wants the number of tasks in each group to be non-increasing from left to right. In one move, a single task can be shifted from any group to its immediate neighbor (either to the left or right). More formally, you can select a group i (tasks[i] > 0) and do one of the following: - If i > 1, move one task from group i to group i - 1 (the previous group). After this move, tasks[i] decrease by 1 and tasks[i-1] increase by 1. - If i < n, move one task from group i to group i + 1 (the next group). After this move, tasks[i] decrease by 1 and tasks[i+1] increase by 1. Determine the minimum number of moves required to rearrange the tasks so that the array becomes non-increasing."
Join thousands of developers practicing for De-shaw.