<p>Given two integers <code>a</code> and <code>b</code>, return <strong>any</strong> string <code>s</code> such that:</p>

<ul>
	<li><code>s</code> has length <code>a + b</code> and contains exactly <code>a</code> <code>&#39;a&#39;</code> letters, and exactly <code>b</code> <code>&#39;b&#39;</code> letters,</li>
	<li>The substring <code>&#39;aaa&#39;</code> does not occur in <code>s</code>, and</li>
	<li>The substring <code>&#39;bbb&#39;</code> does not occur in <code>s</code>.</li>
</ul>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> a = 1, b = 2
<strong>Output:</strong> &quot;abb&quot;
<strong>Explanation:</strong> &quot;abb&quot;, &quot;bab&quot; and &quot;bba&quot; are all correct answers.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> a = 4, b = 1
<strong>Output:</strong> &quot;aabaa&quot;
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>0 &lt;= a, b &lt;= 100</code></li>
	<li>It is guaranteed such an <code>s</code> exists for the given <code>a</code> and <code>b</code>.</li>
</ul>

class Solution {
public:
    string strWithout3a3b(int a, int b) {
        string ans = "";
        int len = 0;
        char prev;
        int cnt = 0;
        int target_len = a+b;
        while(ans.size() != target_len){
            if(a>b){
                if(ans.size() == 0 || (prev == 'a' && cnt < 2) || (prev == 'b')){
                    ans += "a";
                    if(prev == 'a'){
                        cnt++;
                    }
                    else{
                        prev = 'a';
                        cnt = 1;
                    }
                    a--;
                }
                else{
                    ans += "b";
                    if(prev == 'b'){
                        cnt++;
                    }
                    else{
                        prev = 'b';
                        cnt = 1;
                    }
                    b--;
                }
            }
            else{
                if(ans.size() == 0 || (prev == 'b' && cnt < 2) || (prev == 'a')){
                    ans += "b";
                    if(prev == 'b'){
                        cnt++;
                    }
                    else{
                        prev = 'b';
                        cnt = 1;
                    }
                    b--;
                }
                else{
                    ans += "a";
                    if(prev == 'a'){
                        cnt++;
                    }
                    else{
                        prev = 'a';
                        cnt = 1;
                    }
                    a--;
                }
            }
        }
        return ans;
    }
};
7300