Company: Visa

Difficulty: medium

Problem Statement

Minimum Server Hops A data centre has n servers numbered 0 through n - 1 . Server i has capacity capacity[i] , and the capacities are given in strictly increasing order, so capacity[0] < capacity[1] < ... < capacity[n - 1] . The distance between two servers i and j is |capacity[i] - capacity[j]| . The closest server to server i is the server j != i whose distance to i is smallest. The input guarantees that no server has a tie, so every server has exactly one closest server whenever n >= 2 . You may move directly between a server and its closest server, in either direction. That move costs exactly 1 hop no matter how far apart the two capacities actually are. No other move is allowed. You are given q queries. Each query gives two servers from and to . For each query, report the minimum number of hops needed to reach to starting from from , or -1 if to cannot be reached from from at all. Input Format The first line contains a single integer n , the number of servers. The seco

More Visa OA questionsInterview experiences