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.
I'm using Scala but I had a similar problem, until I've implemented the ranked union-find data structure - surprisingly enough, you don't even need the path compression to make it work fast enough - I'm assuming Haskell will give you similar results, as I've only used pure immutable structures. Read the Wikipedia article about disjoint sets - it has everything you need - it's simpler than it looks at first.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Prison Transport
You are viewing a single comment's thread. Return to all comments →
I'm using Scala but I had a similar problem, until I've implemented the ranked union-find data structure - surprisingly enough, you don't even need the path compression to make it work fast enough - I'm assuming Haskell will give you similar results, as I've only used pure immutable structures. Read the Wikipedia article about disjoint sets - it has everything you need - it's simpler than it looks at first.