Easiest Java Solution For Beginners 🔥🔥🔥🔥
\n\n# Complexity\n- Time complexity:\nO(N)\n\n- Space complexity:\nO(N)\n\n# Code\n\nclass Solution {\n    public int numberOfSubstrings(String s) {\n        \n
\n\n# Complexity\n- Time complexity:\nO(N)\n\n- Space complexity:\nO(N)\n\n# Code\n```\nclass Solution {\n    public int numberOfSubstrings(String s) {\n        \n    int count=0;\n\n    int[] arr=new int[3];\n\n    int j=0;\n\n    for(int i=0;i<s.length();i++){\n\n    if(arr[0]>0&&arr[1]>0&&arr[2]>0){\n\n    if(s.charAt(i)==\'a\')arr[0]--;\n    if(s.charAt(i)==\'b\')arr[1]--;\n    if(s.charAt(i)==\'c\')arr[2]--;\n    count+=(s.length()-j+1);\n    continue;\n\n    }\n\n    if(j==s.length())break;\n\n    while(j<s.length()&&(arr[0]==0||arr[1]==0||arr[2]==0)){\n\n    if(s.charAt(j)==\'a\')arr[0]++;\n    if(s.charAt(j)==\'b\')arr[1]++;\n    if(s.charAt(j)==\'c\')arr[2]++;\n    \n    j++;\n\n    }\n\n    if(arr[0]>0&&arr[1]>0&&arr[2]>0)\n    count+=(s.length()-j+1);\n\n    if(s.charAt(i)==\'a\')arr[0]--;\n    if(s.charAt(i)==\'b\')arr[1]--;\n    if(s.charAt(i)==\'c\')arr[2]--;\n\n    }\n\n\n    return count;\n\n\n    }\n}\n```
['Hash Table', 'String', 'Sliding Window', 'Java']