• + 0 comments

    I tested it and it's faster than the simple iterative solution. The Counter initialization is a one time task. The part that constructs t and checks if t meets the required criterion is also O(n) and, without checking the counts, it would run for n*(n-1)/2 times (where n = len(s)). Checking the counts before doing all this would avoid that O(n) operation, when unnecessary. The overall running time is therefore less with the Counter based logic.