Pregunta de entrevista de Meta

Leetcode medium question, look them up!