Skip to content

Files

This branch is 2510 commits behind AnasImloul/Leetcode-Solutions:main.

Number of Substrings Containing All Three Characters

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Aug 17, 2022
Aug 31, 2022
Sep 9, 2022
Sep 4, 2022
Aug 21, 2022
Aug 17, 2022

1358. Number of Substrings Containing All Three Characters

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.

 

Example 1:

Input: s = "abcabc"
Output: 10
Explanation: The substrings containing at least one occurrence of the characters ab and c are "abc", "abca", "abcab", "abcabc", "bca", "bcab", "bcabc", "cab", "cabc" and "abc" (again). 

Example 2:

Input: s = "aaacb"
Output: 3
Explanation: The substrings containing at least one occurrence of the characters ab and c are "aaacb", "aacb" and "acb". 

Example 3:

Input: s = "abc"
Output: 1

 

Constraints:

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