Skip to content

Practice Number of Substrings Containing All Three Characters

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1358
LeetCode Problem

Number of Substrings Containing All Three Characters

Problem Statement

Given a string s consisting only of characters a, b and c. Return the number of substrings containing at least one occurrence of all these characters a, b and c.

Source: Number of Substrings Containing All Three Characters on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "abcabc"
Output
10

# Example 2

Input
s = "aaacb"
Output
3

# Example 3

Input
s = "abc"
Output
1

Constraints

3 <= s.length <= 5 x 10^4
s only consists of a, b or c characters.

Related LeetCode Problems

Practice more problems similar to Number of Substrings Containing All Three Characters.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.