BNY Interview Question

coding question based on dynamic programming