Google Interview Question

question based on dynamic programming