642. Missing Binary Word

Medium3.5 points estimatedStringBacktrackingHash Table3 hints

You are given a list words of different binary words (made of the characters 0 and 1), all of the same length L. The list is shorter than the number of binary words of that length, so at least one word of length L is missing from it.

Return any binary word of length L that is not in the list. Many answers are usually correct, so a checker verifies that the returned word has length L, uses only 0 and 1, and is not in words.

Example 1

Input:
words = ["01","10"]
Output:
"00"
Explanation:

The words 00 and 11 are missing. Any of them is accepted; the reference answer is the smallest one, 00.

Example 2

Input:
words = ["0"]
Output:
"1"
Explanation:

Only 1 is missing.

Example 3

Input:
words = ["000","001","010","011","100"]
Output:
"101"
Explanation:

The missing words are 101, 110 and 111; the smallest, 101, is the reference answer.

Constraints

  • 1 ≤ L ≤ 16 and 1 ≤ words.length < 2^L, with words.length ≤ 100
  • All words have length L, contain only 0 and 1, and are pairwise different.

How this problem is judged

Answers
Any valid answer is accepted. A checker tests yours against the problem's rules.

Expected complexity

Time
O(m * L)
Space
O(m * L)

What the author was aiming for. Your own solution is not measured against it.

Asked in an interview

Were you asked this in an interview? Say where, anonymously.

Code
Loading the editor…