BNY interview question

coding question based on dynamic programming