Company: Publicis Sapient_2Sept
Difficulty: medium
Minimum Server Connection Cost Problem Description There are n servers in a 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 the absolute difference of their capacities, |capacity[i] - capacity[j]| . For each server i , its closest server is the server j != i with the smallest distance to i , and this closest server is unique. To manage the network, the following operations can be performed from a 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 1 unit. You are given m queries, each defined by two integers fromServer[i] and toServer[i] . For each query, find the minimum cost required to connect from server fromServer[i] to server toServer[i] . The connection can be direct, or routed through any number of intermediate servers, paying for every operatio