Pergunta de entrevista da empresa Whatnot

Mapping and DFS problem, hard to finish in time.