-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
"Find Unique Binary String" solution
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class Solution: | ||
def findDifferentBinaryString(self, nums: list[str]) -> str: | ||
assert nums | ||
|
||
n = len(nums[0]) | ||
ints = {int(x, base=2) for x in nums} | ||
|
||
for x in range(2**n): | ||
if x not in ints: | ||
return bin(x)[2:].rjust(n, "0") | ||
|
||
raise ValueError("no unique strings") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import pytest | ||
|
||
from src.find_unique_binary_string import Solution | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"nums,expected", | ||
( | ||
( | ||
["01", "10"], | ||
"00", | ||
), | ||
( | ||
["00", "01"], | ||
"10", | ||
), | ||
( | ||
["111", "011", "001"], | ||
"000", | ||
), | ||
( | ||
["11111", "01001", "00010", "10100", "11101"], | ||
"00000", | ||
), | ||
( | ||
["0"], | ||
"1", | ||
), | ||
), | ||
) | ||
def test_solution(nums, expected): | ||
assert Solution().findDifferentBinaryString(nums) == expected |