• + 3 comments

    I still have some doubt if anyone could explain it. I understand that it is making use of difference array to keep track of the difference between items rather than updating every item.

    However as I understand, size of difference array is one less than total items in the actual array.

    So as per the demo program given,

          	  ARR						DIFF
    (5,3)  0    0    0    0    0		0    0     0    0
    (1,2)  100  100  0    0    0		0    -100  0    0
    (2,5)  100  200  100  100  100		100  -100  0    0
    (3,4)  100  200  200  200  100		100  0     0    -100
    

    However the logic used seems to be a variant of difference array that I am not able to understand. It would be great if someone could help me connect the dots from this difference array to the actual working solution of this problem. Thanks.