-
Notifications
You must be signed in to change notification settings - Fork 65
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
Maple - Christine #31
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,51 @@ def possible_bipartition(dislikes): | |
""" Will return True or False if the given graph | ||
can be bipartitioned without neighboring nodes put | ||
into the same partition. | ||
Time Complexity: ? | ||
Space Complexity: ? | ||
Time Complexity: O(N + E) | ||
Space Complexity: O(N) | ||
""" | ||
pass | ||
|
||
if not dislikes: | ||
return True | ||
|
||
queue = deque() | ||
dogs = set() | ||
group_1 = set() | ||
group_2 = set() | ||
|
||
if dislikes[0]: | ||
start = 0 | ||
else: | ||
start = 1 | ||
Comment on lines
+20
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider an edge case where |
||
|
||
queue.append(start) | ||
dogs.add(start) | ||
group_1.add(start) | ||
|
||
while len(queue): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🦴 Very nice BFS implementation! |
||
current = queue.popleft() | ||
|
||
for disliked_dog in dislikes[current]: | ||
if disliked_dog not in dogs: | ||
dogs.add(disliked_dog) | ||
queue.append(disliked_dog) | ||
if current in group_1: | ||
group_2.add(disliked_dog) | ||
else: | ||
group_1.add(disliked_dog) | ||
elif disliked_dog in dogs: | ||
if current in group_1 and disliked_dog in group_1: | ||
return False | ||
elif current in group_2 and disliked_dog in group_2: | ||
return False | ||
|
||
return True | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✨