Maximum Number of Subsequences After One Inserting

You are given a string s consisting of uppercase English letters.

You are allowed to insert at most one uppercase English letter at any position, including the beginning or end of the string.

Return the maximum number of "LCT" subsequences that can be formed in the resulting string after at most one insertion.

Example 1
Inputs = "LMCT"
Output2
We can insert an "L" at the beginning of s to make "LLMCT", which has 2 subsequences at indices [0, 3, 4] and [1, 3, 4].
Example 2
Inputs = "LCCT"
Output4
We can insert an "L" at the beginning of s to make "LLCCT", which has 4 subsequences at indices [0, 2, 4], [0, 3, 4], [1, 2, 4], and [1, 3, 4].

Constraints

  • 1 <= s.length <= 10^5
  • s consists of uppercase English letters.

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate