Microsoft interview question

related to dynamic programming question