What is the approach to solve this

Given an array of N numbers greater than or equal to zero corresponding to the number of stones at each position, find the minimum number of moves to distribute these stones such that each position has one stone at the end.

The total sum of the given array is equal to N.

A move consists of moving any number of stones from one index to the adjacent one.

Example:-
Input – [0 2 1 3 0 0]
Expected Output – 3

Explanation – Step 1: Shift 1 stone from index 1 to index 0 [1 1 1 3 0 0]
Step 2: Shift 2 stones from index 3 to index 4 [1 1 1 1 2 0]
Step 3: Shift 1 stone from index 4 to index 5 [1 1 1 1 1 1]

@sanchit.bansal06 plz help me

@Par1hsharma,
I can think of a simple approach.

for every index add a[i] - 1 to the sum. Store the index where the sum becomes negative say n1. And when the sum becomes 0 or greater than 0, store that as p1. Now the steps from n1 to p1 will be p1-n1. In case the sum becomes 0 or positive, reset the indexes and add them to total steps

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.