JPMorganChase interview question

Both questions on simple array manipulation with straightforward optimizing