You are viewing a single comment's thread. Return to all comments →
Hi, your solution works but I am not convinced!
I don't see how do you increment all elements between lower and upper!
Can you please explain? Thanks.
It's a difference array. He is storing the difference/the changes that should be made in each index and then runs a loop to add up all these changes. You increment the lower bound because everything inbetween the lower and upper bound should be incremented but you dont want this change to continue for the rest of the array so you decrement at (upper+1).
but how can we know about the upper index of a particular increment,when we are adding all at a once in a loop?