Amazon Interview Question

LUDO solution based on DP,