<p>Given two binary strings <code>a</code> and <code>b</code>, return <em>their sum as a binary string</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> a = "11", b = "1"
<strong>Output:</strong> "100"
</pre><p><strong class="example">Example 2:</strong></p>
<pre><strong>Input:</strong> a = "1010", b = "1011"
<strong>Output:</strong> "10101"
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= a.length, b.length &lt;= 10<sup>4</sup></code></li>
	<li><code>a</code> and <code>b</code> consist&nbsp;only of <code>&#39;0&#39;</code> or <code>&#39;1&#39;</code> characters.</li>
	<li>Each string does not contain leading zeros except for the zero itself.</li>
</ul>

class Solution {
public:
    string addBinary(string a, string b) {
        string ans;
        int carry=0;
        int an, bn;
        unordered_map <char, int> intmap= {{'0',0}, {'1',1}};
        int i=a.size()-1,j=b.size()-1;
        while (i>=0 || j>=0){
            an=0; bn=0;
            if (i>=0) an =intmap[a[i]];
            if (j>=0) bn = intmap[b[j]];
            int s = carry+an+bn;
            int curr = s%2;
            ans.push_back('0'+curr);
            carry=s/2;
            printf("%d, %d, %d, %d, %d, %d\n",i, j, an, bn, curr, carry);
            i-=1; j-=1;

        }
        if (carry) ans.push_back('0'+carry);
        printf("-------------\n");
        for (auto c: ans) printf("%d, ",int(c));
        reverse(ans.begin(), ans.end());
        return ans ;
    
        
    }
};
9500