Solve Two Array Optimization Problems | Amazon Interview Question