I think the question is framed wrong. The minimum number of operations required should be the sum of all transfers. But according to the editorial, it is the maximum value of transfer.
BALIFE | Explain question
hello @manisini.chakraborty
we are doing same only.
no its not like that. we are taking sum of transfers.
check code again
@aman212yadav
For this example
16 17 15 0 20 1 1 2
Our average is 9.
So, First,
We transfer 7 from 16 to 17(Transfer 1, but 7 times). So transfer_count = 7
Array is:
9 24 15 0 20 1 1 2
Now, We transfer (24 - 9) 15 to the next element. So transfer_count = 7 + 15 = 22
Array is
9 9 30 0 20 1 1 2
Now we transfer (30 -9) 21 to the next element. So transfer_count = 22 + 21 = 43
Array is
9 9 9 21 20 1 1 2
Now we transfer (21 - 9) 12 to the next element. So tranfer_count = 43 + 21 = 64
Array is
9 9 9 9 32 1 1 2
Now we transfer (32 - 9) 23 to the next elemet. So transfer_count = 64 + 23 = 87
(This 23 is the maximum value of transfer and hence the answer that is being shown)
Array is:
9 9 9 9 9 24 1 2
Now we transfer (24 - 9) 15 to next element. So transfer_count = 87 + 15 = 102
Array is:
9 9 9 9 9 9 16 2
Finally we transfer 7 from 16 to 2 . Transfer_count = 102 + 7 = 109.
Array is: 9 9 9 9 9 9 9 9.
So answer should be 109.
yeah as per the question description this should be ur answer.
but what additional they are doing(not mentioned in question) is they are ignoring the count to retransfer( u transfer from i to i+1,and then i+1 to i+2 then they are not counting this operation again ) thats why urs answer is not matching with them.
as per question description ur approach is correct.
in code implementation it should be
diff+= abs(a[i]-load); instead of diff+=a[i]-load;
Yes , thank you, please convey to coding blocks to update the the question a bit more and add clarifications.
Thanks for your help.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.