C++ Solution || Easy Approach 
IntuitionThe problem requires us to count the number of substrings that contain all three characters ('a', 'b', and 'c') at least once.The key observation is th

# Intuition
The problem requires us to count the number of substrings that contain all three characters ('a', 'b', and 'c') at least once. 

The key observation is that for every index `i`, the number of valid substrings ending at `i` is determined by the earliest occurrence of any character among 'a', 'b', or 'c' in the substring.

# Approach
- Maintain an array `seen[3]` to track the last occurrence of 'a', 'b', and 'c'.
- Iterate through the string and update the last seen index for each character.
- The number of substrings ending at the current index `i` that include all three characters is determined by the minimum of the last seen indices of 'a', 'b', and 'c'.
- Add this count to the result.

# Complexity
- **Time Complexity:** $$O(n)$$ since we traverse the string once.
- **Space Complexity:** $$O(1)$$ as we use only a fixed amount of extra space.

# Code
```cpp
class Solution {
public:
    int numberOfSubstrings(string s) {
        int cnt = 0;
        int n = s.size();
        int seen[3] = {-1, -1, -1};
        
        for (int i = 0; i < n; i++) {
            seen[s[i] - 'a'] = i;
            cnt += 1 + min({seen[0], seen[1], seen[2]});
        }
        return cnt;
    }
};
```

![d3550b79-52c8-4704-846f-c00daecb5632_1737784461.667478.png](https://assets.leetcode.com/users/images/b8d28f10-0ca5-4282-b621-18bcabc80b6f_1741670539.4784338.png)


['Hash Table', 'String', 'C++']