codes of n distinct binary strings, each exactly n characters long. Build a code of the same length that is guaranteed not to be on the list.
Here is how: count the ones in every string. Find the smallest number k from 0 to n such that no string on the list has exactly k ones (there are n strings but n + 1 possible counts, so such a k always exists). Return the string of k ones followed by n - k zeros.codes=["00", "11"] → '10'
The codes have 0 and 2 ones, and no code has exactly 1. The answer is one 1 followed by zeros: "10".
codes=["010", "110", "001"] → '000'
The counts of ones are 1, 2 and 1. Zero ones never occurs, so the answer is "000".
codes=["0"] → '1'
Zero ones is taken and one 1 is free: "1".
0 and 1codes are distinctcodes=["00", "11"]
'10'
Run checks the first 3 tests in your browser. Submit checks all 16 tests on the server, hidden ones included.