JPMorganChase Interview Question

Both questions on simple array manipulation with straightforward optimizing