cswork / OA打开练习工作台

ZipRecruiterOA #14

Triplets With Unique Chars

简单可在线判题

考点(AI 标注)双指针滑窗字符串

Given a string s containing only lowercase English letters, count the consecutive triplets in s made of pairwise distinct characters. In other words, count the indices i for which s[i], s[i+1], s[i+2] are pairwise different.

输入格式

One line with the string s. 1≤length of s≤1000, containing only lowercase English letters.

输出格式

Output one integer.

样例 1

输入:

abcdaaae

输出:

3

样例 2

输入:

abacaba

输出:

2

样例 3

输入:

xyz

输出:

1

样例说明

Example 1: s="abcdaaae"; i=0 (abc), i=1 (bcd), and i=2 (cda) qualify; in i=3 (daa), s[4] and s[5] are the same, and all later triplets also contain repeated characters, so the answer is 3. Example 2: s="abacaba"; only i=1 (bac) and i=3 (cab) qualify, and every other triplet contains two a's, so the answer is 2. Example 3: s="xyz" has only one triplet, which qualifies, so the answer is 1.