Python 3 : Elegant with explanation
This is a python version of the Java solution posted by @manrajsingh007 That is a beautiful solution.\n\n### Explanation\n\nThe idea is to calculate the number 
**This is a python version of the Java solution posted by @manrajsingh007 That is a [beautiful solution](https://leetcode.com/problems/number-of-substrings-containing-all-three-characters/discuss/516955/Java-ELEGANT-No-Sliding-Window-EXPLAINED-(No-of-Sub-Strings-Ending-at-Curr-Index)).**\n\n### Explanation\n\nThe idea is to calculate the number of substrings ending at index `i` as you traverse the input string from `i = 0` to `n-1`\n\nWe maintain an array `last` of size 3 to track the positions of the 3 characters `a`, `b` and `c` . \n\nAs we traverse the input string, for each `i = 0` to `n -1`, we have \n* `s[min(last) : i+1]` is ths shortest substring with all 3 characters `a`, `b` and `c`\n*  Additionally, there are `min(last)` new substrings due to the characters from index `min(last)-1`  to `0` which can be prepended to the shortest substring that we derived in the previous step. \n\nConsider the input string `aaabcc`\n\n`a a a b c c`\n`| | | | | |`\n`0 1 2 3 4 5`\n\n* For `i = 0`, `last = [0, -1, -1]` and `min(last) = -1`\n\n* For `i = 1`,  `last = [1, -1, -1]` and `min(last) = -1`\n* For  `i = 2`, `last = [2, -1, -1]` and `min(last) = -1`\n* For `i = 3`, `last = [2,   3,  -1]` and `min(last) = -1`\n* For `i = 4`, `last = [2,   3,   4]` and  `min(last) = 2`. \n\t* So, this adds `2 + 1 = 3` substrings to the final result.\n\t* The substrings are `abc`, `aabc` and `aaabc`\n* For `i = 5`, `last  = [2, 3, 5]` and `min(last) = 2`\n\t* So, this adds `2 + 1 = 3` substrings to the final result\n\t* The susbtrings are `abcc`, `aabcc` and `aaabcc`\n\n* Final result = 6\n\n### Code\n\n```\nclass Solution:\n    def numberOfSubstrings(self, s: str) -> int:\n        # As you iterate count the number of substrings ending at index i\n        result = 0\n        \n        last = [-1] * 3\n        \n        for i, c in enumerate(s):\n            \n            last[ord(c) - ord(\'a\')]  = i\n            \n            result += (min(last) + 1)\n            \n        return result\n```
[]