JavaScript Solution - Greedy Approach
The way I solved this problem was thinking about which letter we want to prioritize at each point. If the last two consecutive letters were a mixture of "ab" or
The way I solved this problem was thinking about which letter we want to prioritize at each point. If the last two consecutive letters were a mixture of "ab" or "ba", then we want to use up the letter we have more. However, if the last two letters were "aa", then we would need to use "b" here because of the constraint of no "aaa". This applies to "bb" also. I used two additional variables to count the consecutive letters and reset them as needed.\n\n```\nvar strWithout3a3b = function(a, b) {\n    const n = a + b;\n  \n    let consecutiveAs = 0;\n    let consecutiveBs = 0;\n    \n    let res = "";\n    \n    for (let i = 0; i < n; i++) {\n        if (consecutiveAs < 2 && consecutiveBs < 2) {\n            if (a > b) {\n                res += "a";\n                consecutiveAs++;\n                a--;\n                consecutiveBs = 0;\n            }\n            else {\n                res += "b";\n                consecutiveBs++;\n                b--;\n                consecutiveAs = 0;\n            }\n        }\n        else if (consecutiveAs == 2) {\n            res += "b";\n            consecutiveBs++;\n            b--;\n            consecutiveAs = 0;\n        }\n        else {\n            res += "a";\n            consecutiveAs++;\n            a--;\n            consecutiveBs = 0;\n        }\n    }\n    \n    return res;\n}; \n```
['Greedy', 'JavaScript']