Domanda di colloquio di Meta

Is it the otimize solution? What time complexity that solution?