Solve Two Array Optimization Problems | Google Coding Question