Pergunta de entrevista da empresa JPMorganChase

Both questions on simple array manipulation with straightforward optimizing