Facebook challenge problem on bipartite Graph