Amazon interview question

methods for optimization