Amazon interview question

Standard Algo question ; kept adding different constraints to make problem progressively more difficult ; very interesting.