Pergunta de entrevista da empresa Amazon

One coding question based on DFS