Company: Razorpay
Difficulty: medium
Servers Time In a compute cluster, worker nodes sometimes relay their partial results toward one coordinating node, called the master, which merges everything together. Your cluster has n nodes, numbered 1 through n , and node n is always the master. Node i may forward a message directly to node i + sendTime[i] or to node i - sendTime[i] , whenever a node with that number actually exists. Each direct forward costs exactly 1 second, and a channel can carry any number of messages at once. Every node wants its own message to eventually reach the master. How quickly can each node's message get there? For each node, work out the smallest number of seconds needed for its message to reach the master. If a node has no route to the master at all, its answer should be -1 . Input Format The first line contains an integer, n , the number of nodes. Each of the following n lines contains one integer sendTime[i] , the hop distance node i can forward across. Output Format An integer array giving the m