Number of Substrings Containing All Three Characters

Counting Subarrays and Fixed Window DSA practice problem on Onlearn.

Difficulty: medium.

Topics: Number of substrings containing all three characters, Strings, String Manipulation, Substrings, Loops, Frequency Counting, Sliding Window, Brute Force, Time Complexity, Space Complexity, Optimization, string, string properties, sliding window, frequency counting, two pointer technique, Subarray/Substring Problems, Frequency Counting.

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 that contain at least one occurrence of all these three characters. Input Specification The input consists of a single string s. Output Specification Return an integer representing the total count of such substrings. Constraints 1 <= s.length <= 10^5 s consists only of characters 'a', 'b', and 'c'. Sample Test Cases Sample Input 1: Sample Output 1: Explanation 1: The substrings containing 'a', 'b', and 'c' are "abc", "abca", "abcab", "abcabc", "bca", "bcab", "bcabc", "cab", "cabc", "abc". Sample Input 2: Sample Output 2: Explanation 2: The substrings containing 'a', 'b', and 'c' are "aaacb", "aacb", "acb". Sample Input 3: Sample Output 3: