Pregunta de entrevista de Meta

It was leetcode based question. A slight modification