3628. Maximum Number of Subsequences After One Inserting Medium

@problem@discussion
#String#Dynamic Programming#Greedy#Prefix Sum



1/**
2 * [3628] Maximum Number of Subsequences After One Inserting
3 *
4 * You are given a string s consisting of uppercase English letters.
5 * You are allowed to insert at most one uppercase English letter at any position (including the beginning or end) of the string.
6 * Return the maximum number of "LCT" <span data-keyword="subsequence-string-nonempty">subsequences</span> that can be formed in the resulting string after at most one insertion.
7 *  
8 * <strong class="example">Example 1:
9 * <div class="example-block">
10 * Input: <span class="example-io">s = "LMCT"</span>
11 * Output: <span class="example-io">2</span>
12 * Explanation:
13 * We can insert a "L" at the beginning of the string s to make "LLMCT", which has 2 subsequences, at indices [0, 3, 4] and [1, 3, 4].
14 * </div>
15 * <strong class="example">Example 2:
16 * <div class="example-block">
17 * Input: <span class="example-io">s = "LCCT"</span>
18 * Output: <span class="example-io">4</span>
19 * Explanation:
20 * We can insert a "L" at the beginning of the string s to make "LLCCT", which has 4 subsequences, at indices [0, 2, 4], [0, 3, 4], [1, 2, 4] and [1, 3, 4].
21 * </div>
22 * <strong class="example">Example 3:
23 * <div class="example-block">
24 * Input: <span class="example-io">s = "L"</span>
25 * Output: <span class="example-io">0</span>
26 * Explanation:
27 * Since it is not possible to obtain the subsequence "LCT" by inserting a single letter, the result is 0.
28 * </div>
29 *  
30 * Constraints:
31 * 
32 * 	1 <= s.length <= 10^5
33 * 	s consists of uppercase English letters.
34 * 
35 */
36pub struct Solution {}
37
38// problem: https://leetcode.com/problems/maximum-number-of-subsequences-after-one-inserting/
39// discuss: https://leetcode.com/problems/maximum-number-of-subsequences-after-one-inserting/discuss/?currentPage=1&orderBy=most_votes&query=
40
41// submission codes start here
42
43impl Solution {
44    pub fn num_of_subsequences(s: String) -> i64 {
45        
46    }
47}
48
49// submission codes end
50
51#[cfg(test)]
52mod tests {
53    use super::*;
54
55    #[test]
56    fn test_3628() {
57    }
58}
59

Back
© 2026 bowen.ge All Rights Reserved.