All problems
0592MediumArrayHash TableStringBacktracking

An Unissued Badge Code

Tracked in this browser only
Write code

Trains the technique from

LeetCode 1980Find Unique Binary String

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

A depot stamps access badges with fixed-width codes. A code of width n is a row of n characters where each character is either 0 or 1.

You are handed nums, the list of codes already stamped. It holds exactly n codes, every one of them of width n, and no two of them are the same.

Return a code of width n, again built only from the characters 0 and 1, that does not appear in nums. Usually more than one code qualifies. When that happens, return the qualifying code that comes earliest in dictionary order.

There are 2^n codes of width n and nums lists only n of them, so a qualifying code always exists.

Examples

Example 1

Input
nums = ["000", "001", "010"]
Output
"011"

`011` has width three, uses only `0` and `1`, and is not one of the three stamped codes. Every width-three code ahead of it in dictionary order, namely `000`, `001` and `010`, is stamped.

Example 2

Input
nums = ["1101", "0000", "1000", "0111"]
Output
"0001"

`0001` is unstamped, while `0000` is stamped, so nothing earlier in dictionary order qualifies.

Example 3

Input
nums = ["11010", "01001", "10111", "00011", "11100"]
Output
"00000"

None of the five stamped codes is `00000`, and no width-five code precedes it in dictionary order.

Constraints

  • n == nums.length
  • 1 <= n <= 16
  • nums[i].length == n
  • Every character of nums[i] is either '0' or '1'.
  • No code appears twice in nums.

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def find_different_binary_string(nums: list[str]) -> str:
Java
public String findDifferentBinaryString(String[] nums)
September 7
Apply