Google Interview Question

Question based on array and vectors and then optimization.