Company: Flexport_26nov
Difficulty: medium
Optimal Transfer Optimal Transfer Problem Description A network contains n servers listed in ascending order of capacity. The array capacity stores each server's capacity, so server i has capacity capacity[i] for 0 ≤ i < n . The distance between servers i and j is the absolute difference of their capacities: |capacity[i] - capacity[j]| . Every server i has one uniquely-determined closest server j — the one sitting at the smallest distance from it. From any server x , the network lets you do either of the following to set up a connection: Connect straight to any server y , paying |capacity[x] - capacity[y]| units. Connect to x 's closest server for a flat cost of one unit. You're given m queries, each made up of two integers fromServer[i] and toServer[i] . For every query, work out the cheapest way to get from fromServer[i] to toServer[i] , whether that means connecting directly or hopping through other servers along the way. Note: All capacities in the capacity array are distinct