Pregunta de entrevista de JPMorganChase

Both questions on simple array manipulation with straightforward optimizing