Microsoft interview question

Question on Stack and Dynamic Programming