Loading...
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.
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.
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.
demands.length ≤1000demands[i].length =3amount ≤100from < to ≤1000capacity ≤105Click "Run" to test with sample cases or "Submit" to run all tests.