Design Gurus Logo
Number of Substrings Containing All Three Characters (medium)

Problem Statement

Given a string s containing only a, b, and c characters, return the number of substrings containing at least one occurences of a, b and c characters.

Examples

  • Example 1:

    • Input: "abc"
    • Expected Output: 1
    • Justification: The string itself ("abc") is the only substring containing all three characters.
  • Example 2:

    • Input: "abbcca"
    • Expected Output: 5
    • Justification: The substrings containing all 3 characters are "abbc", "abbcc", "abbcca", "bbcca", and "bcca".
  • Example 3:

    • Input: "ababacb"
    • Expected Output: 9
    • Justification: The substrings containing all 3 characters are "ababac", "babac", "abac", "bac", "ababacb", "babacb", "abacb", "bacb", and "acb".

Try it yourself

Try solving this question here:

Python3
Python3

. . . .

.....

.....

.....

Unlock this and all other premium problems.
No code editor for this lesson
This lesson focuses on concepts and theory