Pregunta de entrevista de bp

Algorithm question with complexity analysis