2055. Plates Between Candles Medium
1/**
2 * [2055] Plates Between Candles
3 *
4 * There is a long table with a line of plates and candles arranged on top of it. You are given a 0-indexed string s consisting of characters '*' and '|' only, where a '*' represents a plate and a '|' represents a candle.
5 * You are also given a 0-indexed 2D integer array queries where queries[i] = [lefti, righti] denotes the substring s[lefti...righti] (inclusive). For each query, you need to find the number of plates between candles that are in the substring. A plate is considered between candles if there is at least one candle to its left and at least one candle to its right in the substring.
6 *
7 * For example, s = "||**||**|*", and a query [3, 8] denotes the substring "*||<u>**</u>|". The number of plates between candles in this substring is 2, as each of the two plates has at least one candle in the substring to its left and right.
8 *
9 * Return an integer array answer where answer[i] is the answer to the i^th query.
10 *
11 * Example 1:
12 * <img alt="ex-1" src="https://assets.leetcode.com/uploads/2021/10/04/ex-1.png" style="width: 400px; height: 134px;" />
13 * Input: s = "**|**|***|", queries = [[2,5],[5,9]]
14 * Output: [2,3]
15 * Explanation:
16 * - queries[0] has two plates between candles.
17 * - queries[1] has three plates between candles.
18 *
19 * Example 2:
20 * <img alt="ex-2" src="https://assets.leetcode.com/uploads/2021/10/04/ex-2.png" style="width: 600px; height: 193px;" />
21 * Input: s = "***|**|*****|**||**|*", queries = [[1,17],[4,5],[14,17],[5,11],[15,16]]
22 * Output: [9,0,0,0,0]
23 * Explanation:
24 * - queries[0] has nine plates between candles.
25 * - The other queries have zero plates between candles.
26 *
27 *
28 * Constraints:
29 *
30 * 3 <= s.length <= 10^5
31 * s consists of '*' and '|' characters.
32 * 1 <= queries.length <= 10^5
33 * queries[i].length == 2
34 * 0 <= lefti <= righti < s.length
35 *
36 */
37pub struct Solution {}
38
39// problem: https://leetcode.com/problems/plates-between-candles/
40// discuss: https://leetcode.com/problems/plates-between-candles/discuss/?currentPage=1&orderBy=most_votes&query=
41
42// submission codes start here
43
44impl Solution {
45 pub fn plates_between_candles(s: String, queries: Vec<Vec<i32>>) -> Vec<i32> {
46 vec![]
47 }
48}
49
50// submission codes end
51
52#[cfg(test)]
53mod tests {
54 use super::*;
55
56 #[test]
57 fn test_2055() {
58 }
59}
60
Back
© 2025 bowen.ge All Rights Reserved.