Solve Prime Jumps and Pipeline Scaling
Company: Uber
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This question evaluates algorithmic problem-solving skills in constrained path optimization and resource-allocation throughput maximization, including concepts such as graph modelling with prime-step constraints, dynamic programming, number-theoretic reasoning, and combinatorial optimization.
Part 1: Prime-Constrained Score Jump
Constraints
- 1 <= len(score) <= 5000
- -100000 <= score[i] <= 100000
- 0 <= k <= 5000
- A jump length must be prime, so length 1 is not allowed.
Examples
Input: ([5, -2, 4, 10, -1], 3)
Expected Output: 8
Explanation: Valid jump lengths are 2 and 3. The only way to reach index 4 is 0 -> 2 -> 4, giving 5 + 4 - 1 = 8.
Input: ([10, -100, -5, 20, 1, 50], 3)
Expected Output: 80
Explanation: The best path is 0 -> 3 -> 5 using jumps of length 3 and 2, for a total of 10 + 20 + 50 = 80.
Input: ([7, 5], 3)
Expected Output: None
Explanation: The only distance to the last index is 1, which is not prime, so the last index is unreachable.
Input: ([-5], 1)
Expected Output: -5
Explanation: The start index is already the last index, so the answer is score[0].
Input: ([1, 2, 3], 1)
Expected Output: None
Explanation: No prime jump length is at most 1, so no move can be made from index 0.
Hints
- First generate all prime jump lengths up to min(k, len(score) - 1).
- Use dynamic programming: let dp[i] be the best total score achievable when landing on index i.
Part 2: Maximize Pipeline Throughput
Constraints
- 1 <= len(t) == len(cost) <= 100000
- 1 <= t[i] <= 1000000
- 1 <= cost[i] <= 1000000
- 0 <= budget <= 1000000000000
- Each service can be expanded only an integer number of times.
Examples
Input: ([10, 20, 30], [5, 10, 15], 10)
Expected Output: 20
Explanation: Spend 5 to expand the first service once, raising it to 20. Reaching 25 or more would require also expanding the second service and would exceed the budget.
Input: ([7], [3], 10)
Expected Output: 28
Explanation: With one service, spend at most 10 on expansions costing 3 each. Three expansions are possible, so throughput is 7 * 4 = 28.
Input: ([5, 8, 3], [2, 2, 2], 0)
Expected Output: 3
Explanation: With zero budget, no expansions are possible, so the throughput remains the minimum base throughput, 3.
Input: ([4, 7], [5, 100], 20)
Expected Output: 7
Explanation: The first service can be raised to at least 7, but raising the second service above 7 costs 100, which is not affordable.
Input: ([3, 5, 10], [4, 6, 100], 18)
Expected Output: 10
Explanation: Target 10 costs 12 for the first service and 6 for the second service, exactly using the budget. Target 11 would require expanding the third service, which is too expensive.
Hints
- For a proposed target throughput X, compute the minimum number of expansions each service needs to reach at least X.
- The feasibility of a target throughput is monotonic: if X is affordable, then every smaller target is also affordable.