TikTok interview question

I got a dynamic programming question.