Company: Publicis Sapient_2Sept
Difficulty: medium
Minimum Server Connection Cost Problem Description There are n servers in the network arranged in ascending order of their capacity. In the array capacity , the capacity of the i th server is capacity[i] , where 0 ≤ i < n . The distance between two servers, i and j , is defined as the absolute difference in their capacities: |capacity[i] - capacity[j]| . For each server i , the closest server j is the one with the smallest distance to i , and this closest server is unique. To manage the network, the following operations can be done to server x : Connect to any server y at a cost of |capacity[x] - capacity[y]| units. Connect to the closest server of x for a fixed cost of one unit. Given m queries, each defined by two integers fromServer[i] and toServer[i] , find the minimum cost required to connect from fromServer[i] to toServer[i] for each query. The connection can be either direct or routed through a server z . Note: The values in the capacity array are distinct. Function Descri