Pregunta de entrevista de Amazon

Medium difficulty coding Q about connected components.