1. Server Traffic Monitor
There is client-server architecture with n clients and one server. Each client starts its interaction with the server at the second start[i] and stops at the second end[i]. The maximum traffic is defined as the maximum number of concurrent interactions with the server.
Find the earliest time at which the maximum number of clients are interacting with the server.
Note: The endpoint is also included in the interaction.
Example
Suppose start = [1, 6, 2, 9] and end = [8, 7, 6, 10]
Time | Connection | Active Clients |
---|---|---|
1 | Client 1 Joined | 1 |
2 | Client 3 Joined | 1, 3 |
3 | 1, 3 | |
4 | 1, 3 | |
5 | 1, 3 | |
6 | Client 2 Joined | 1, 2, 3 |
7 | Client 3 Left | 1, 2 |
8 | Client 2 Left | 1 |
9 | Client 1 Left and Client 4 Joined | 4 |
10 | 4 | |
11 | Client 4 Left |
The maximum number of concurrent interactions is 3, which happens first at the 6th second. Return 6.
Function Description
Complete the function getMaxTrafficTime in the editor below.
getMaxTrafficTime has the following parameters:
- INTEGER_ARRAY start
- INTEGER_ARRAY end
Returns
- INTEGER: the earliest second at which the maximum number of clients are interacting with the server
Constraints
- 1 ≤ n ≤ 100000
- 1 ≤ start[i], end[i] ≤ 1000000000
2. Maximum Throughput
In our system, we have a pipeline consisting of data processing units, each with varying throughputs as represented by throughput[i]. These units are arranged in a series, requiring data to pass through each of them sequentially. Consequently, the total throughput of the pipeline is constrained by the unit with the smallest throughput, which becomes the bottleneck limiting the overall processing speed.
Each service can be scaled up independently, with the cost of scaling up the ith service one unit equal to scaling_cost[i]. After scaling up a service x times, it can process throughput[i] * (1 + x) messages per minute.
Given the arrays throughput and scaling_cost, both of size n, and an integer budget representing the budget available, determine the optimal scaling configuration for the services such that the throughput generated by the nth service is maximized.
Example
For instance, throughput = [4, 2, 7], scaling_cost = [3, 5, 6], and budget = 32.
To maximize the throughput of the final service, an optimal solution is:
Service Index | Scale From | Scale To | Times Scaled | Cost per Scaling | Total Cost |
---|---|---|---|---|---|
0 | 4 | 12 | 2 | 3 | 6 |
1 | 2 | 10 | 4 | 5 | 20 |
2 | 7 | 14 | 1 | 6 | 6 |
When these units are applied in series, they generate a throughput of 10 units, the maximum possible throughput given the budget. Hence the answer is 10.
Function Description
Complete the function getMaximumThroughput in the editor below.
getMaximumThroughput has the following parameters:
- INTEGER_ARRAY throughput: the throughput generated by each of the n services
- INTEGER_ARRAY scaling_cost: the cost of scaling up a service one time
- INTEGER budget: the available money
Returns
- LONG INTEGER: the maximum value of the throughput generated at the end of the composite service after scaling within the budget
Constraints
- 1 ≤ n ≤ 100000
- 1 ≤ throughput[i] ≤ 10000000
- 1 ≤ scaling_cost[i] ≤ 200
- 1 ≤ budget ≤ 1000000000000000000
CSOAhelp长期稳定承接各大科技公司如TikTok、Google、Amazon等的OA笔试代写服务,确保满分通过。如有需求,请随时联系我们。
CSOAhelp consistently provide professional online assessment services for major tech companies like TikTok, Google, and Amazon, guaranteeing perfect scores. Feel free to contact us if you're interested.