Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

[(1, 2, 3), (2, 4, 5)] would result in a graph like this:

1 - 2 - 3

     \

      4 - 5
Building the (undirected) graph would take linear time, and once it is built, you can do a simple Depth First Search to mark all the connected components.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: