Skip to content

1980. Find Unique Binary String #1338

Answered by mah-shamim
mah-shamim asked this question in Q&A
Discussion options

You must be logged in to vote

We need to find a binary string of length n that does not appear in the given array nums. The solution leverages a clever approach based on Cantor's diagonal argument to efficiently construct such a string.

Approach

The key idea is to construct a binary string where each bit is chosen such that it differs from the corresponding bit in each of the strings in nums at a specific position. Specifically, for the i-th position of the resulting string, we take the i-th bit of the i-th string in nums and flip it (0 becomes 1 and 1 becomes 0). This ensures that the resulting string will differ from every string in nums in at least one position, guaranteeing that it is not present in the array.

Let…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@basharul-siddike
Comment options

@mah-shamim
Comment options

mah-shamim Feb 20, 2025
Maintainer Author

Answer selected by basharul-siddike
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants