Skip to content

Conversation

piffer59
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.

Really nice work Heather. I like the BFS solution you wrote here. Well done. I don't think it catches when there are two unconnected groups of nodes. Take a look and see if you agree or not.


if group_hash[disliked_dog]
return false if group_hash[disliked_dog] == parent_group
elsif !group_hash[disliked_dog]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just do:

Suggested change
elsif !group_hash[disliked_dog]
else

# add first, connected node to q & group_hash
count = 0
i = 0
until count == 1 && i < dislikes.length

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the graph is unconnected like:

adjacency_list = {
  1 => [2, 3],
  2 => [1, 3],
  3 => [1, 2],
  4 => [5, 6],
  5 => [4, 6],
  6 => [4, 5]
}

In this graph there are two unconnected groups of nodes. I'll update my tests to catch this scenario.

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