Skip to main content
Back to problems
Leetcode
Medium
Arrays
Strings
Backtracking
Google
Find Unique Binary String

Given nn distinct binary strings of length nn, construct any binary string of length nn that does not appear in the list.

Acceptance 100%
Problem Statement

You are given an array of nn distinct binary strings, where each string has length nn. Your task is to return any binary string of length nn that is not present in the array.

A binary string contains only the characters 0 and 1. Because the input list contains nn unique strings of length nn, it is guaranteed that at least one valid answer exists.

This is a constructive problem: you do not need to find the lexicographically smallest answer, only any missing binary string is acceptable.

Input Format

Input

  • An integer nn implied by the size of the array.
  • An array of nn distinct binary strings, each of length nn.

Assumptions

  • All strings contain only 0 and 1.
  • All strings in the array are unique.

Output Format

Output

  • Return any binary string of length nn that does not occur in the given array.

Constraints

  • 1n161 \le n \le 16 for typical interview reasoning.
  • The array contains exactly nn distinct strings.
  • Each string has length exactly nn.
  • Each character is either 0 or 1.

Note: The core guarantee is that a missing string always exists.

Examples
Sample cases returned by the problem API.

Example 1

Input

nums = ["01","10"]

Output

"11"

Explanation

There are four binary strings of length 2: 00, 01, 10, and 11. Since 11 is not in the list, it is a valid answer.

Example 2

Input

nums = ["111","011","001"]

Output

"010"

Explanation

Any binary string of length 3 that is not one of the three inputs is acceptable. Here, 010 is missing.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.