Domanda di colloquio di Meta

Technical algorithm question with choice of language.