Pregunta de entrevista de Eightfold

How this code runs and explain time and space complexity?