Question: You have n boxes. You are given a binary string boxes of length n , where boxes [ i ] is ' 0 ' if
You have n boxes. You are given a binary string boxes of length n where boxesi is if the ith box is empty, and if it contains one ball.
In one operation, you can move one ball from a box to an adjacent box. Box i is adjacent to box j if absi j Note that after doing so there may be more than one ball in some boxes.
Return an array answer of size n where answeri is the minimum number of operations needed to move all the balls to the ith box.
Each answeri is calculated considering the initial state of the boxes.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
