How would improve this O(n^2 ) string manipulation solution? : Write a function that takes in an input of a string and returns the count of tuples.
Tuples in the form (x,y) where x = index of 'a', y = index of 'b' and x < y.


Examples: For “aab” the answer is two
 For "ababab" the answer is six

It can be done in O(n^2) by simply looking for the number of b's after each 'a' but I'm not sure how to do it in O(n).
I've tried traversing the string with 2 pointers but I keep missing some tuples. I'm not sure if this can be done in O(n) time.
