You are given a 2D integer array demands and an integer capacity.
Each demands[i] = [amount, from, to] adds amount to a running load over the half-open position range [from, to): the load is present at every position x with from <= x < to, and is gone again at to itself.
Return true if the total load never exceeds capacity at any position, and false if it does at any point.
Examples
Example 1
Input: demands = [[2,1,5],[3,3,7]], capacity = 4
Output: false
Explanation: From position 3 up to position 5 both demands are active, so the load there is 2 + 3 = 5, which exceeds the capacity of 4.
Example 2
Input: demands = [[2,1,5],[3,3,7]], capacity = 5
Output: true
Explanation: The same overlap reaches a load of 5, which is within the capacity of 5, and no position carries more.
Constraints
1≤demands.length≤1000
demands[i].length=3
1≤amount≤100
0≤from<to≤1000
1≤capacity≤105
Loading editor...
Log in to run your code. Your draft is saved in this browser.Log inSign up