Hackerrank problem solving practice | Roads and Libraries
1 min readFeb 23, 2020
Graph related problem is really charming because this kind of problem usually seems very complicated but can be solved by a delicate tricky method or certain data structure. This problem is named “Roads and libraries”, more explanation of it can be found in the link I attached. In short, implementation of disjoint set or dfs can make it easy to pass.
The time complexity constraint based on given info is very lossen for disjoint set method.
The first solution is based on dfs.
The second solution is based on disjoint set.