C++ Simple || 100 % Faster || Greedy || With Comments
There can be 3 sitautions a>b, b>a and a=b;\nas we need to avoid three a and b so we greedly doing the following:-\nif(a>b) res.append("aab")\nif(b>a) res.appen
There can be 3 sitautions a>b, b>a and a=b;\nas we need to avoid three a and b so we greedly doing the following:-\nif(a>b) res.append("aab")\nif(b>a) res.append("bba")\nelse res.append("ab")\n\nyou might be thinking what if we will be using more numbers of a and b. there is a trick at the end we will be taking substring of this resultant string of size (a+b).\nnow go through the code you will get better insight.\n\nif you find it help full please upvote.\n\n```\nclass Solution {\npublic:\n    string strWithout3a3b(int a, int b) {\n        int size=a+b;\n        string res="";\n        while(a||b){\n            if(a>b){\n               res+="aab"; \n                a-=2;\n                b-=1;\n                a=max(0,a);\n                b=max(0,b);\n            }\n            else if(b>a){\n               res+="bba"; \n                a-=1;\n                b-=2;\n                a=max(0,a);\n                b=max(0,b);\n            } \n            else{\n               res+="ab";\n                b-=1;\n                a-=1;\n                b=max(0,b);\n                a=max(0,a);\n            }\n        }\n        return res.substr(0,size);\n    }\n};\n```
[]