Pregunta de entrevista de Meta

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