The Number of Ways to Earn Points problem gives you a list of tasks, each with a maximum count and a score. You want to earn exactly a target number of points. Count the number of ways to select tasks (picking each task type between 0 and its max count times) to hit the target exactly. This is a bounded knapsack counting problem.
TuSimple asks this because it's a clean extension of the 0/1 knapsack to bounded quantities. The key distinction from unbounded knapsack: each task type has a maximum count. The array and dynamic programming interview pattern is demonstrated through the bounded knapsack variant.
Bounded knapsack DP. dp[j] = number of ways to earn exactly j points. For each task type (count c, score s): update DP in reverse (0/1 knapsack style, but for bounded count). For each number of uses u from 1 to c: dp[j] += dp[j-u*s]. Or use the sliding window optimization for O(target * n) time.
tasks=[(3,1),(2,2)], target=4. (Can use type1 up to 3 times at 1 point each, type2 up to 2 times at 2 points each.) After type1: dp = [1,1,1,1,0] (ways to earn 0..4 using type1). After type2:
Bounded knapsack counting is more complex than 0/1 or unbounded variants. The standard approach loops over each item type and each usage count. For efficiency with large counts, use the sliding window deque optimization to compute the DP for each item in O(target) time regardless of max count. Practice all three knapsack variants (0/1, bounded, unbounded) to handle any variant that appears in interviews.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Arithmetic Slices II - Subsequence | Hard | Solve | |
| Best Time to Buy and Sell Stock III | Hard | Solve | |
| Best Time to Buy and Sell Stock IV | Hard | Solve | |
| Burst Balloons | Hard | Solve | |
| Choose Numbers From Two Arrays in Range | Hard | Solve |