Pergunta de entrevista da empresa Meta

Technical algorithm question with choice of language.