Solve Two Array Optimization Problems | Amazon Coding Question