Calculate the average number of dresses per machine.
Don't worry about each machine should borrow dresses or give out dresses, transform all to give-out => machines[i] = machines[i] - average, yes you can give out a negative amount to dresses.
Max(machines[i]) should be the answer, yes at least you need to do machines[i] operations to give out machines[i] dresses.
Wait, what if there is an accumulated number of give-outs that's greater than Max(machines[i])? Then use that accumulated number as the answer since those two give-outs can happen simultaneously. Example: [1, 1, 1, 0, -5, 0, 2], 1 + 1 + 1 > 2, so answer is 1 + 1 + 1 = 3.
@wz366 your solution will not work for this case
in this case, the average dresses per machine is 4. and the array of machines[i]-average is
in this case maximum give out is 7, there are no accumulated give outs that are more than 7, so according to your algorithm, the solution is 7. But the actual answer is 8.
Can you Please explain your algorithm or correct me if i have understood it wrong.
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.