Pregunta de entrevista de UST

Asked to solve a leetcode question.