Trains the technique from
LeetCode 1980Find Unique Binary StringThis 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.
Example 1
`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
`0001` is unstamped, while `0000` is stamped, so nothing earlier in dictionary order qualifies.
Example 3
None of the five stamped codes is `00000`, and no width-five code precedes it in dictionary order.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def find_different_binary_string(nums: list[str]) -> str:public String findDifferentBinaryString(String[] nums)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.