Amazon interview question

Color Fill Problem from leetcode