100 % in both , 3 pointer approach SUPER EASY
just maintain three pointers to hold most recent indices of a,b and c . then the number of substrings at any index lets say with char c is the most closest inde
just maintain three pointers to hold most recent indices of a,b and c . then the number of substrings at any index lets say with char c is the most closest index to left from where a and b are found +1 for the new substring . \n```\nclass Solution {\n    public int numberOfSubstrings(String s) {\n        int ans = 0;\n        \n        //char[] str = s.toCharArray();\n  \n        // Stores recent index of the characters \n        int a_index = -1; \n        int b_index = -1; \n        int c_index = -1; \n        int n = s.length();\n        for (int i = 0; i < n; i++)  \n        { \n  \n            // If character is a update a\'s index \n            // and the variable ans \n            if (s.charAt(i) == \'a\')  \n            { \n                a_index = i;\n                if(b_index!=-1 && c_index!=-1){\n                    \n                    ans = ans + Math.min(b_index,c_index) +1;\n                }\n                \n            }  \n            // If character is b update b\'s index \n            // and the variable ans \n            else if (s.charAt(i) == \'b\') \n            { \n                b_index = i;\n                if(a_index!=-1 && c_index!=-1){\n                    ans = ans + Math.min(a_index,c_index) +1;\n                }\n                \n            }  \n            // If character is c update c\'s index \n            // and the variable ans \n            else \n            { \n                c_index = i;\n                if(b_index!=-1 && a_index!=-1){\n                    ans = ans + Math.min(a_index,b_index) +1;    \n                }\n                \n            } \n        } \n        return(ans);\n    }\n}\n```
['Java']