Skip to content

ian-rossi/server-connections-challenge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

The challenge

Server connection

To send a message, server x connects to two different servers y and z (x != y, y != z, z != x). The two servers are connected only if the distance between them is divisible by signalSpeed. It then sends the signal across the network. For each server i, the company wants to know the number of disjoint pairs of servers through which the server can send a message. Return an array of serverNodes integers, where the ith integer represents the number of disjoint pairs of serfvers (j, k) through which server i can send a message.

Example

  • serverNodesQuantity = 4
  • serversFrom = [1, 1, 2]
  • serversTo = [2, 3, 4]
  • serverWeights = [2, 5, 3]
  • signalSpeed = 5
graph TD
    1 -- 2 --> 2
    1 -- 5 --> 3
    2 -- 3 --> 4
Loading

For server 1, the valid pairs are (3, 4) and (4, 3). The distances sum to 5 between 1 and 4 and between 1 and 3 are divisible by signalSpeed = 5. For server 2, there are no valid pairs. Distances are 3, 2 and 7 to servers 4, 1 and 3 respectively. For server 3, the valid pairs are (1, 4) and (4, 1). For server 4, the valid pairs are (1, 3) and (3, 1). Return the number of pairs for each server. In this case, is [2, 0, 2, 2]

Function description

Complete the function getNumPairs in the editor below.

getNumPairs has the following parameters:

  • int serverNodesQuantity: the number of servers
  • int[] serversFrom[serverNodesQuantity - 1]: one end of the edge
  • int[] serversTo[serverNodesQuantity - 1]: other end of the edge
  • int[] serverWeights[serverNodesQuantity - 1]: the distance between the connected servers
  • int signalSpeed: the speed of the signal

Constraints

  • 2 <= serverNodesQuantity <= 1000
  • 1 <= serversFrom[i], serversTo[i] <= n
  • 1 <= serversWeights[i] <= 10**6
  • 1 <= signalSpeed <= 1000

The solution

Techniques used

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy