Leetcode Problem 2055. Plates Between Candles

2055. Plates Between Candles

Leetcode Solutions

Prefix Sum and Binary Search

  1. Initialize an array prefixSum to store the cumulative count of plates up to each index.
  2. Initialize a list candles to store the indices of candles.
  3. Iterate through the string s and update prefixSum and candles accordingly.
  4. For each query [left, right], perform binary search on candles to find the closest candle index to the right of left and the closest candle index to the left of right.
  5. Calculate the number of plates between these two candles using the prefixSum array.
  6. Store the result for each query in a list result and return it.
UML Thumbnail

Next Candle Precomputation

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...