#2055

Plates Between Candles

specialist · 910 · lc medium +31 · verified · 47.4% accepted · 1,355 likes · top 32%

Description

A string s consists of '*' (plates) and '|' (candles). For each query [left, right], count the plates strictly between the leftmost and rightmost candles within s[left..right]. Return an array answer where answer[i] is the result of the i-th query.

Example 1:

Input: s = "**|**|***|", queries = [[2,5],[5,9]]
Output: [2,3]
Explanation:
- queries[0] has two plates between candles.
- queries[1] has three plates between candles.

Example 2:

Input: s = "***|**|*****|**||**|*", queries = [[1,17],[4,5],[14,17],[5,11],[15,16]]
Output: [9,0,0,0,0]
Explanation:
- queries[0] has nine plates between candles.
- The other queries have zero plates between candles.

Code

1
2
3