Design 2D DP on a DAG | Amazon Interview Question