Pregunta de entrevista de Amazon

Basic coding questions, a lot of algorithm analysis