Microsoft Interview Question

Sort a given array into 3 parts. Connected components of a graph.