As reported: Palo Alto Networks software engineer online assessment (US, 2026), intermediate section (60 minutes for two problems), problem 1.
There are n servers numbered 1..n, sorted in ascending order of capacity; server i has capacity capacity[i], all distinct. The distance between servers i and j is |capacity[i] − capacity[j]|. Each server's closest server (the one at the smallest distance) is unique.
From a server x you can:
- connect to any server
yat cost|capacity[x] − capacity[y]|, or - connect to the closest server of
xat cost1.
You get m queries (fromServer[i], toServer[i]). For each, return the minimum total cost to connect from fromServer[i] to toServer[i], directly or by routing through other servers.
Example
capacity = [0,8,12,15,20]
fromServer = [1,1,3,5,3]
toServer = [4,5,2,3,3]
-> [3,8,4,2,0]
Closest servers: 1→2, 2→3, 3→4, 4→3, 5→4. Query 1→4: 1→2→3→4, each hop to the closest server, cost 3. Query 5→3: 5→4 (cost 1), 4→3 (cost 1).
Constraints: 2 ≤ n ≤ 10^5; 0 ≤ capacity[i] ≤ 10^9, strictly increasing; 1 ≤ m ≤ 10^5.
Code runner format: three lines — capacity, fromServer, toServer (JSON arrays, servers 1-indexed). Implement minConnectCost(capacity, fromServer, toServer); the harness prints the list of costs.