GlobalLogic Interview Question

Question from dynamic programming and data structure