-
Notifications
You must be signed in to change notification settings - Fork 16
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
Shubha 🧙♀️ #9
base: master
Are you sure you want to change the base?
Shubha 🧙♀️ #9
Conversation
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.
This definitely works and I like the edge-cases you have in your tests. I had some minor quibbles and I was suspicious that it didn't handle all disconnected graphs, but it seems to do so. Nice work!
@@ -1,4 +1,43 @@ | |||
# I looked at the leetcode solution in Python | |||
# (https://leetcode.com/problems/possible-bipartition/solution/) |
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.
Ok great, it's been a while since you saw graphs in class anyway.
lib/possible_bipartition.rb
Outdated
|
||
def build_graph(dislikes) | ||
nodes = Hash.new {|h,k| h[k] = [] } #had to look up how to do this on StackOverflow | ||
dislikes.each do |dislike| |
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.
Minor thing: You don't need to indent here.
lib/possible_bipartition.rb
Outdated
if queue.empty? && node < graph.keys.max | ||
queue.push(node + 1) | ||
end |
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.
This doesn't seem like the most efficient way to handle a disconnected graph. Maybe also check to ensure that grouped[node].nil?
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.
I updated this to seek the next ungrouped node. It gets rid of a lot of the aimless wandering of the last approach, but still doesn't seem very efficient. Thoughts?:
if queue.empty?
graph.keys.each do |key|
if grouped[key].nil?
queue.push(key)
break
end
end
end
No description provided.