[Python3] greedy O(N)
Algo\nHere, the strategy is that we choose b whenever we can. Now the question is when it is impossible to put b. There are 2 cases \n1) I just put 2 bs in plac
**Algo**\nHere, the strategy is that we choose `b` whenever we can. Now the question is when it is impossible to put `b`. There are 2 cases \n1) I just put 2 `b`s in place;\n2) there ain\'t enough `b` left to guarentee no `aaa` (here, the condition to avoid this situation is `2*b < a`). \n\n**Implementation**\n```\nclass Solution:\n    def strWithout3a3b(self, a: int, b: int) -> str:\n        ans = []\n        while a and b: \n            if ans[-2:] == ["b"]*2 or 2*b < a: \n                ans.append("a")\n                a -= 1\n            else: \n                ans.append("b")\n                b -= 1\n        ans.extend(a*["a"] + b*["b"])\n        return "".join(ans)\n```\n\n**Analysis**\nTime complexity `O(N)`\nSpace complexity `O(N)`\n\nA few words for the 2nd condition. \nSuppose we put a `b` in the current place. Then, there are `b-1` `"b"`s left which are enough to host at most `b` chunks of `"aa"`. So if there are more `"a"` than `2*b`, then we have to put in an `"a"`. Otherwise, a `"aaa"` is guarenteed to occur.
['Python3']