Pregunta de entrevista de Tesla

Leetcode like question about algorithms