LeetCode 1358, Medium. Topics: Hash Table, String, Sliding Window. View on LeetCode.
Generate this problem as a practice environment: tested reference solution, 16 parametrized pytest cases, and a playground notebook:
Problem
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.
Examples
Constraints
- 3 <= s.length <= 5 * 10^4
- s only consists of ‘a’, ‘b’ or ‘c’ characters.
Solution
Reference implementation from solution.py on GitHub, full suite in test_solution.py:
Complexity
NeetCode All. Last modified on September 7, 2026