RBC Interview Question

Array manipulation, improve code effiency