TikTok Interview Question

dynamic programming, hard hard questions