Amazon interview question

Optimization Problem