Find Unique Binary String
Real-world version: An Unissued Badge CodeThe statement here is our own: the same inputs, outputs and technique.
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 starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def find_different_binary_string(nums: list[str]) -> str:public String findDifferentBinaryString(String[] nums)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 10 test cases: 10 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Word Break IIReal-world version: Tape Track SplitsHard
- Maximum Score Words Formed by LettersReal-world version: Best Tile Rack PlayHard
- Stickers to Spell WordReal-world version: Cutting Letters Out of StencilsHard
- Verifying an Alien DictionaryReal-world version: Catalogue Order Under a Custom Glyph SequenceEasy