Amazon interview question

1 Dp based question and 1 graph based