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

Shubha 🧙‍♀️ #9

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Conversation

shubha-rajan
Copy link

No description provided.

Copy link

@CheezItMan CheezItMan left a 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/)

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.


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|

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.

Comment on lines 26 to 28
if queue.empty? && node < graph.keys.max
queue.push(node + 1)
end

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?

Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants