SALESFORCE Coding Question – Solved

9 Live
2. Salesforce Latency Optimization Given a Salesforce infrastructure with API nodes, cloud regions, and API edges (bidirectional API connections between them), the i-th connection links regions api_from[i] and api_to[i] with a latency of api_weight[i]. The max-latency of a region is the maximum latency of any API within that region. Split this infrastructure into at most k independent regions by disabling some API connections such that the maximum of the max-latency of all regions formed is minimized. Given api_nodes, api_from, and api_to, determine the minimum possible value of the maximum max-latency of the regions formed. Example: Suppose: api_nodes = 3 m = 3 k = 2 api_from = [1, 2, 3] api_to = [2, 3, 1] api_weight = [4, 5, 3] Function Description: Complete the function optimizeAPIRegions in the editor below. optimizeAPIRegions has the following parameter(s): - api_nodes: the number of cloud regions - api_from[api_edges]: one endpoint of the API connections - api_to[api_edges]: the other endpoint of the API connections - api_weight[api_edges]: the latency of the API connections - k: the maximum number of regions after disabling some APIs Returns: - int: the minimum possible value of the maximum of max-latency of the networks formed Constraints: - 1 ≀ api_nodes ≀ 10^5 - 0 ≀ api_edges ≀ 1.5 Γ— 10^5 - 1 ≀ api_from[i], api_to[i] ≀ api_nodes - 1 ≀ api_weight[i] ≀ 10^9 - 1 ≀ k ≀ n - It is guaranteed that the graph is initially connected. Input Format For Custom Testing: Sample Case 0: Sample Input For Custom Testing: STDIN: api_nodes = 2, api_edges = 1 api_from = [1] api_to = [2] api_weight = [3] k = 1 Sample Output: 3 Explanation: In this case, the graph has 2 nodes connected by 1 API edge with latency 3. Since we are allowed to create only 1 region (k=1), the minimum possible value of the maximum latency of the network is 3.

Asked in: SALESFORCE

Image of the Question

Question Image Question Image Question Image Question Image Question Image

All Testcases Passed βœ”



Passcode Image

Solution


Please login to view the solution


Related Questions

| You are given a board of size M Γ— N where each cell can be either empty ('O') o… |
| Undirected Coloured Graph Shortest Path You are given an undirected weight… |
| Village Voyage A computer game "Village Voyage" has N villages (labeled 1 to… |
| Academic Decathlon Students are being selected for an academic decathlon tea… |
| Sum of Arrays Given two arrays each of length n, arr1 and arr2, in one opera… |
| Count Swaps During Custom Sorting Analyze the efficiency of the following so… |