Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

c17 jae clayton #76

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion graphs/possible_bipartition.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,29 @@ def possible_bipartition(dislikes):
Time Complexity: ?
Space Complexity: ?
"""
pass
groups = {}
# create list of all the dogs, arr of dogs
for dog in dislikes.keys():
queue = deque()
queue.append(dog)
while queue:
current = queue.popleft()
if current not in groups:
groups[current] = True
# grab the value for current dog
# this will be a list of all the dogs current dog can't be with
disliked_dogs = dislikes[current]
for bad_dog in disliked_dogs:
if bad_dog not in groups:
# set the value to false for the dogs current dog
# cannot be paired with
groups[bad_dog] = not groups[current]
# add current bad_dog to the queue
queue.append(bad_dog)
else:
if groups[bad_dog] == groups[current]:
return False
return True