Number of Substrings Containing All Three Characters
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
You are given a string s made only of the characters 'a', 'b', and 'c'.
Count the substrings (contiguous, non-empty) that contain **at least one** of each of the three characters. Substrings at different positions are counted separately even if their text is identical.
Return the count. An O(n) solution is expected.
Examples
Constraints
- 3 <= s.length <= 5 * 10^4
- s consists only of 'a', 'b', and 'c'
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.