#1980
Medium Algorithms Find unique binary string
Array Hash Table String Backtracking
79.4% acceptance
Feb 25, 2026
2562
89
Given an array of strings nums containing n unique binary strings each of length n, return a binary string of length n that does not appear in nums. If there are multiple answers, you may return any of them.
Solution
Rust
Time O(n)
Space O(1)
impl Solution {
pub fn find_different_binary_string(nums: Vec<String>) -> String {
// Cantor's diagonal argument: differ from nums[i] at position i
nums.iter()
.enumerate()
.map(|(i, s)| {
if s.as_bytes()[i] == b'0' { '1' } else { '0' }
})
.collect()
}
}