TikTok Interview Question

Dynamic programming question found on leetcode