C++ || Easy-Explanation ||Simplest-Solution || No Hash Map
Approach\n- Told in the code\n\n# Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(1)\n Add your space complexity here, e.g. O(n) \n\n# Code\n\nclas
# Approach\n- Told in the code\n\n# Complexity\n- Time complexity: $$O(n)$$\n\n- Space complexity: $$O(1)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    // We will use three pointers to store the index of the last \'a\', \'b\' and \'c\' character\n// We will iterate over the string and update the pointers\n// We will check if the current index is greater than 1\n// If the current index is greater than 1, we will add the minimum of the three pointers to the result\n// The minimum of the three pointers will give us the index of the last character in the substring\n// We will add 1 to the index of the last character in the substring to get the number of substrings\n// We will return the result\nint numberOfSubstrings(string s)\n{\n    int a_index = -1;\n    // We will store the index of the last \'a\' character\n    int b_index = -1;\n    // We will store the index of the last \'b\' character\n    int c_index = -1;\n    // We will store the index of the last \'c\' character\n    int result = 0;\n    // We will store the number of substrings\n    for (int index = 0; index < s.size(); index++)\n    {\n        // We will iterate over the string\n        if (s[index] == \'a\')\n            a_index = index;\n        if (s[index] == \'b\')\n            b_index = index;\n        if (s[index] == \'c\')\n            c_index = index;\n        if (index > 1)\n            result += std::min({a_index, b_index, c_index}) + 1;\n        // We will add the minimum of the three pointers to the result\n    }\n    return result;\n}\n};\n```
['String', 'Brainteaser', 'Sliding Window', 'C++']