I have done this question from solution But not able to understand the logic

I have done this question from solution
But not able to understand the logic.
Can You please explain logic or approach how to think this way.


hello @cbcao263

let say startvalue is x
then after each iteration ur value will varie as->

x+a[0], x+a[0]+a[1], x+a[0]+a[1]+a[2] ,…so on

now the constraint is all value should be greater than 1 right?

if mimimum value is greater than = 1 then all other value will be greater than = 1.
so to get minimum we sort the array(prefix sum) and pick its minimum(oth index value)
if it is already >= 1 then x=0
otherwise
x+value >= 1
=> x=1-value
so x should be 1-value

1 Like

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.