Count Residue Prefixes

You are given a string s consisting only of lowercase English letters.

A prefix of s is called a residue if the number of distinct characters in the prefix is equal to len(prefix) % 3.

Return the count of residue prefixes in s.

A prefix of a string is a non-empty substring that starts from the beginning of the string and extends to any point within it.

Example 1
Inputs = "abc"
Output2
Prefixes "a" and "ab" satisfy the condition, while "abc" does not, so the answer is 2.
Example 2
Inputs = "dd"
Output1
Prefix "d" satisfies the condition, while "dd" does not, so the answer is 1.

Constraints

  • 1 <= s.length <= 100
  • s contains only lowercase English letters.

Asked at 2 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