As reported: D. E. Shaw online assessment on HackerRank (2025), problem 1, "Optimal Transfer".
There are n servers arranged in ascending order of capacity: capacity[i] is the capacity of server i (0 ≤ i < n). The distance between servers i and j is |capacity[i] − capacity[j]|. For every server i, its closest server is the one at the smallest distance from it, and it is unique.
From server x you can:
- connect to any server
yat a cost of|capacity[x] − capacity[y]|, or - connect to the closest server of
xat a fixed cost of 1.
Answer m queries: for each i, the minimum cost to get from fromServer[i] to toServer[i], directly or through other servers.
Example 1
capacity = [0,8,12,15,20]
fromServer = [0,1,4,2,0]
toServer = [4,0,0,3,0]
Output: [8,8,14,1,0]
0 → 4: hop 0 → 1 (closest, 1), 1 → 2 (closest, 1), 2 → 3 (closest, 1), then 3 → 4 costs 20 − 15 = 5 (server 3's closest is 2): total 8.
Example 2
capacity = [1,5], fromServer = [0,1], toServer = [1,0]
Output: [1,1]
Constraints: 2 ≤ n ≤ 10^5; 0 ≤ capacity[i] ≤ 10^9, strictly increasing; every server's closest server is unique; 1 ≤ m ≤ 10^5; 0 ≤ fromServer[i], toServer[i] < n.
Code runner format: one JSON value per line: capacity, fromServer, toServer. Implement getMinCost(capacity, fromServer, toServer) and return the list of costs (64-bit values).