Count Three-Character Windows Without Repetition

Quick Overview

Count Three-Character Windows Without Repetition. Count length-three contiguous substrings of s whose characters are all different. Count every occurrence, including overlapping occurrences and repeated copies of the same three-letter string.

Count Three-Character Windows Without Repetition

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

### Problem Count length-three contiguous substrings of `s` whose characters are all different. Count every occurrence, including overlapping occurrences and repeated copies of the same three-letter string. ```cpp class Solution { public: int countGoodSubstrings(string s); }; ``` ### Examples **Example 1:** ```text s = "abcabc" Output: 4 Explanation: Windows abc, bca, cab, and abc all qualify. ``` **Example 2:** ```text s = "aabb" Output: 0 Explanation: Both length-three windows repeat a character. ``` ### Constraints - `1 <= s.length <= 100`. - Characters are lowercase English letters. ### Clarifying Questions Count occurrence positions rather than distinct substring texts. Fewer than three characters means no candidate window. ```hint Inspect the structure Are you counting distinct substring texts or every eligible starting position, including overlaps? ``` ### Reasoning checkpoints - Enforce pairwise distinctness across all three characters. - Count eligible start positions with overlap and repeated substring text handled correctly. ### Optional extensions How would a sliding frequency table support an arbitrary window length?

Overview: Count Three-Character Windows Without Repetition. Count length-three contiguous substrings of s whose characters are all different. Count every occurrence, including overlapping occurrences and repeated copies of the same three-letter string.

Amazon logo
Amazon
May 30, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Problem

Count length-three contiguous substrings of s whose characters are all different. Count every occurrence, including overlapping occurrences and repeated copies of the same three-letter string.

class Solution {
public:
    int countGoodSubstrings(string s);
};

Examples

Example 1:

s = "abcabc"
Output: 4
Explanation: Windows abc, bca, cab, and abc all qualify.

Example 2:

s = "aabb"
Output: 0
Explanation: Both length-three windows repeat a character.

Constraints

  • 1 <= s.length <= 100 .
  • Characters are lowercase English letters.

Clarifying Questions Guidance

Count occurrence positions rather than distinct substring texts. Fewer than three characters means no candidate window.

Reasoning checkpoints

  • Enforce pairwise distinctness across all three characters.
  • Count eligible start positions with overlap and repeated substring text handled correctly.

Optional extensions

How would a sliding frequency table support an arbitrary window length?