category-wise-problems

contains category wise problems(data structures, competitive) of popular platforms.

View the Project on GitHub mayankdutta/category-wise-problems

1358. Number of Substrings Containing All Three Characters, Medium, 2 pointers

The atleast method

Approach

some other approaches

Code ```cpp class Solution { public: int numberOfSubstrings(string s) { int a = 0; int b = 0; int c = 0; int left = 0; int ans = 0; for (int right = 0; right < s.size(); right++) { a += (s[right] == 'a'); b += (s[right] == 'b'); c += (s[right] == 'c'); while (a > 0 and b > 0 and c > 0) { a -= (s[left] == 'a'); b -= (s[left] == 'b'); c -= (s[left] == 'c'); left ++; } ans += left; } return ans; } }; ```