Find Maximum Number of Non Intersecting Substrings

You are given a string word.

Return the maximum number of non-intersecting substrings of word that are at least four characters long and start and end with the same letter.

Example 1
Inputword = "abcdeafdef"
Output2
The two substrings are "abcdea" and "fdef".
Example 2
Inputword = "bcdaaaab"
Output1
The only substring is "aaaa"; we cannot also choose "bcdaaaab" since it intersects with the other substring.

Constraints

  • 1 <= word.length <= 2 * 10^5
  • word consists only of lowercase 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