Frage im Vorstellungsgespräch bei Meta

Basic algorithmic question. Improve time and space complexity.