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:
Determine the minimum number of moves required to rearrange the tasks so that the array becomes non-increasing.
1<=tasks.size()<=1e5
Hard