JPMORGAN Coding Question – Solved

7 Live
A company needs an efficient strategy to optimize resource allocation for servers based on performance metrics. The performance of each server is represented by performance[i], where 0 ≀ i < n. A server's rank is defined by the count of distinct performance metrics that are greater than or equal to its own performance metric. To allocate resources, two positive integer constants, inc and dec, are used to determine increment and decrement values, respectively. The resource allocation for each server is calculated as follows: resource allocation = inc Γ— (n + 1 - server's rank) - dec Γ— rank The task is to calculate the resource allocation for each server based on their performance. Example: inc = 500 dec = 100 n = 6 performance = [3, 2, 4, 3, 5, 5] Server index 0 has a rank of 3 since 3, 4, and 5 are greater than or equal to its performance of 3. The resource allocation is calculated as: 500 Γ— (6 + 1 - 3) - 100 Γ— 2 = 1800

Asked in: JPMORGAN

Image of the Question

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… |