public String addBinary(String a, String b) {
        StringBuilder sb = new StringBuilder();
        int i = a.length() - 1;
        int j = b.length() - 1;
        boolean carry = false; // this can only be 1 or 0
        while (i >= 0 || j >= 0) {
            boolean f = false;
            boolean s = false;
            if (i >= 0 && j >= 0) {
                f = a.charAt(i--) == '1';
                s = b.charAt(j--) == '1';
            } else if (i >= 0)
                f = a.charAt(i--) == '1';
            else
                s = b.charAt(j--) == '1';

            if (f && s) {
                sb.insert(0, carry ? 1 : 0);
                carry = true;
            } else if (f || s) {
                sb.insert(0, carry ? 0 : 1);
            } else {
                sb.insert(0, carry ? 1 : 0);
                carry = false;
            }
        }
        if (carry) sb.insert(0, 1);
        return sb.toString();


    }
Problem: Given Two Binary Strings a, b return Binary representation of sum of a and b;
src/problems/easy/AddBinary.java