Conversation
kyra-patton
left a comment
There was a problem hiding this comment.
🐾🐶 Good work, Ainur. I wrote a comment to help point you in the right direction as to why your test cases aren't passing. Let me know what questions you have.
🟡
| Time Complexity: ? | ||
| Space Complexity: ? | ||
| Time Complexity: O(N+E) N-number of nodes, E -number of edges | ||
| Space Complexity: O(N)?? |
There was a problem hiding this comment.
🪐 Yes! Space complexity will be O(N) because the data structures you create, queue, visited, group1, and group2 can each hold at most N nodes (aka dogs).
| into the same partition. | ||
| Time Complexity: ? | ||
| Space Complexity: ? | ||
| Time Complexity: O(N+E) N-number of nodes, E -number of edges |
| group1 = set() | ||
| group2 = set() | ||
|
|
||
| queue.append(0) |
There was a problem hiding this comment.
Your two test cases are failing because you need a guard clause to find the first node in the list that is connected to other nodes in the graph.
Say you have a graph such as this:
dislikes = [ [], [2, 3], [1, 3], [1, 2] ]
If you draw out the graph, you will see that Node 0 is disconnected from the rest of the graph - it has no edges. Because it has no edges/neighbors, nothing else will be added to your queue after you pop Node 0 off the queue and you will return True by default.
No description provided.