TikTok interview question

Dynamic programming (DP) and string manipulation Leetcode-style question.