Pregunta de entrevista de Amazon

some coding question involving arrays