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.
Example 1:
Input: s = "abc"
Output: 2
Explanation:
"a" has 1 distinct character and length modulo 3 is 1, so it is a residue."ab" has 2 distinct characters and length modulo 3 is 2, so it is a residue."abc" does not satisfy the condition. Thus, the answer is 2.Example 2:
Input: s = "dd"
Output: 1
Explanation:
"d" has 1 distinct character and length modulo 3 is 1, so it is a residue."dd" has 1 distinct character but length modulo 3 is 2, so it is not a residue. Thus, the answer is 1.Example 3:
Input: s = "bob"
Output: 2
Explanation:
"b" has 1 distinct character and length modulo 3 is 1, so it is a residue."bo" has 2 distinct characters and length mod 3 is 2, so it is a residue. Thus, the answer is 2.Constraints:
1 <= s.length <= 100s contains only lowercase English letters.Loading editor...
"abc"