package leetcode;

/**
 * https://leetcode.com/problems/find-unique-binary-string/
 */
public class Problem1980 {
    public String findDifferentBinaryString(String[] nums) {
        // TODO
        return null;
    }

    public static void main(String[] args) {
        Problem1980 prob = new Problem1980();
        System.out.println(prob.findDifferentBinaryString(new String[]{"01","10"})); // "11"
        System.out.println(prob.findDifferentBinaryString(new String[]{"00","01"})); // "11"
        System.out.println(prob.findDifferentBinaryString(new String[]{"111","011","001"})); // "101"
    }
}

package leetcode;

import java.util.HashSet;
import java.util.Set;

/**
 * https://leetcode.com/problems/find-unique-binary-string/
 */
public class Problem1980 {
    public String findDifferentBinaryString(String[] nums) {
        Set<String> set = new HashSet<>();
        for (String num : nums) {
            set.add(num);
        }
        return findDifferentBinaryString(set, 0, new char[nums.length]);
    }

    private static String findDifferentBinaryString(Set<String> nums, int index, char[] chars) {
        if (index == nums.size()) {
            String s = new String(chars);
            if (nums.contains(s)) {
                return null;
            }
            return s;
        }
        for (char c : new char[]{'0', '1'}){
            char tmp = chars[index];
            chars[index] = c;
            String s = findDifferentBinaryString(nums, index + 1, chars);
            if (s != null) {
                return s;
            }
            chars[index] = tmp; // Backtrack.
        }
        return null;
    }
}

Solve problem 1980