Pregunta de entrevista de Amazon

Time complexity analysis and improvement.