Number of Connected Components (LeetCode 323)The problem You get nodes labelled to and a list of undirected . Return how…