Solve Prime Jumps and Pipeline Scaling
UberSoftware Engineer · Technical ScreenLast updated
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.
An online assessment contains two independent coding problems. Solve both.
Problem 1: Prime-Constrained Score Jump
You are given an integer array score of length n and an integer k. You start at index 0, and your initial total is score[0]. On each move, you may jump from index i to index j only if:
j > i,j - i <= k, andj - iis a prime number.
When you land on an index, you add score[j] to your total. Return the maximum total score you can obtain when reaching index n - 1. If index n - 1 cannot be reached, return null.
Assume score may contain negative values.
Problem 2: Maximize Pipeline Throughput
You are given a serial processing pipeline with n services. Service i has:
- base throughput
t[i], and - expansion cost
cost[i].
The pipeline throughput is the minimum throughput among all services.
You may expand any service any nonnegative integer number of times. If service i is expanded x times, then:
- its throughput becomes
t[i] * (1 + x), and - the total money spent on that service is
x * cost[i].
Given a total budget budget, return the maximum possible overall pipeline throughput.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.