Skip to content

Instantly share code, notes, and snippets.

@anurag-7
Last active January 13, 2025 12:17
Show Gist options
  • Save anurag-7/64cb94650b19ca6c748b08265cdce625 to your computer and use it in GitHub Desktop.
Save anurag-7/64cb94650b19ca6c748b08265cdce625 to your computer and use it in GitHub Desktop.
class Suite:
def __init__(self, failing: tuple[int, int]):
self.failing = set(failing)
def testSuite(self, arr: list[int]):
return len(set(arr) & self.failing) == 2
def solve(self, n: int):
arr = list(range(n))
result = self.dnc(arr)
print(result)
return arr
def dnc(self, arr: list[int]):
length = len(arr)
# This shouldn't hit unless there's a bug.
if length < 2:
return []
if length == 2:
return arr
mid = length // 2
first, second = arr[:mid], arr[mid:]
if self.testSuite(first):
return self.dnc(first)
elif self.testSuite(second):
return self.dnc(second)
else:
return self.dnc(self.get_valid_array(first, second))
def get_valid_array(self, first, second):
first_mid = len(first) // 2
second_mid = len(second) // 2
to_check = []
to_check.append(first[:first_mid] + second[second_mid:])
to_check.append(first[first_mid:] + second[:second_mid])
to_check.append(first[:first_mid] + second[:second_mid])
to_check.append(first[first_mid:] + second[second_mid:])
for arr in to_check:
if self.testSuite(arr):
return arr
def main():
n = int(input())
first, second = map(int, input().split())
suite = Suite((first, second))
suite.solve(n)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment