Amazon interview question

Leetcode 323 Number of connected components in an Undirected Graph