Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Can you find the indices of the most left and right candles for a given substring, perhaps by using binary search (or better) over an array of indices of all the bars?
Once the indices of the most left and right bars are determined, how can you efficiently count the number of plates within the range? Prefix sums?