• + 0 comments

    Thanks ! If only all lthe explanations above said these words , "cumulative Slope algorithm works, when we add the value K only to the starting index(and assume it is being added until the end), but the Qs wants us to add only until till a index B, Therefore to stop the continous assumtion of adding K even after index B, we must put the index b+1 as -K. Thus from the working of our algorithm all the places form b+1 to end(inclusive) will be summed as (+K )+(-K), this way every new queries have to be started from their A index and ended at B by -K at B+ 1 , Now whe we cumulative add upto each index and replace it with the sum we get the previos ans array which we were getting from brute force "