Domanda di colloquio di LinkedIn

a typical dfs question with complexity analysis