Amazon interview question

basic 2d dp question same as leetcode