459

This problem can be solved using dfs,bfs or union find algorithm,

BFS solution:

 

Leave a Reply

Your email address will not be published. Required fields are marked *