Pregunta de entrevista de Meta

It was a typical coding question. Nothing too complicated