AKUNA CAPITAL interview question

A graph question which was solved using DFS and design elevator system