Domanda di colloquio di MathWorks

Very hard dp leetcode type of question