Manager is supposed to split the members into two teams, we have make the tasks assigned to each member of the team equal either by increasing or decreasing the number of tasks. Find the minimum of moves to make all the tasks to each member in Team A equal as well as for TeamB.
We are given array "Tasks" of size N, where Task[i] is the number of tasks assigned to the i th member.
Here move is defined as incrementing or decrementing the element i.e., 3-> 6 => we need to do 3 moves.
Eg :
N = 4
Tasks = [7 3 2 3]
Answer : 1
Explanation -> TeamA{3,2,3} , TeamB{7}
TeamA - > we can increment 2 to 3. -> 1 move.
TeamB -> 0 moves
total = 1
I tried to sort the array and split it into two teams, now I had to find an element to make elements equal to. Couldn't complete it within time. Any leads on how to solve this question optimally?
[Please comment if you have any doubts regarding the question]
Thanks