Skip to content

Commit

Permalink
"Find Unique Binary String" solution
Browse files Browse the repository at this point in the history
  • Loading branch information
lancelote committed Nov 16, 2023
1 parent 89aeb38 commit 7071120
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/find_unique_binary_string.py
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")
32 changes: 32 additions & 0 deletions tests/test_find_unique_binary_string.py
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

0 comments on commit 7071120

Please sign in to comment.