Google Interview Question

They asked me a question on DP on grids