TikTok interview question

dynamic programming, hard hard questions