Think of the negative numbers as consumers from a warehouse and
positive numbers as producers from the warehouse. The problem reduces
to plotting the inventory (starting from time = 0 to time = n) and then
finding the max amplitude over time axis in +ve quadrant of the
inventory profile which can be done in O(n).

Reply via email to