We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Friend Circle Queries
- Discussions
Friend Circle Queries
Friend Circle Queries
Sort by
recency
|
87 Discussions
|
Please Login in order to post a comment
My Disjoint Set solution. Just a small modification to a dictionnary for the size and parents instead of an array.
in swift
}
At the very beginning, I realized union find was the best solution. But when implementing it, I found
1000000000
would definitely lead to stack overflow if I set the size of vectors as 10^9. Then I found those numbers which hadn't appeared yet would not influence others which had appeared already, so setting vectors with a fixed size was not necessary. Thus, hash map appeared in my solution.can anyone help me what is the problem with this code it is paassing all test case but getting TLE for test case 10, how can i improve that code.
For disjoint sets, I prefer sets over trees. Sets give you O(1) for find and O(n) for union. (Opposite of trees.)