Solve a LeetCode-style coding problem requiring optimization with dynamic programming or greedy techniques.