Pregunta de entrevista de Amazon

coding question with time complexity analysis