Panda Guru LogoPanda
Guru

AMAZON SDE-1 OA

Round 1

Questions:

Question 1:

In managing tasks at analytics platform, the goal is to efficiently schedule both required and optional tasks within specified time constraints. There are n required tasks and n optional tasks. Two arrays, tasksRequired and tasksOptional, provide information on task hours, where tasksRequired[i] represents the duration in hours of the ith required task, and tasksOptional[i] represents the duration in hours of the ith optional task. Each day on the platform has a time limit denoted as dailyTimeLimit in hours. One required task must be scheduled each day. If time remains after the required task, you can choose to schedule at most one optional task on that day. It’s essential to ensure that the total hours does not exceed the specified daily TimeLimit. Determine the maximum number of optional tasks that can be scheduled during these n days while adhering to the given constraints.

Example:

dailyTimeLimit = 7
tasksRequired = [4, 5, 2, 4]
tasksOptional = [5, 6, 3, 4].

Day 1: Schedule the first required task and the third optional task. Total time is 4 + 3 = 7.
Day 2: Schedule the second required task. Total time is 5.
Day 3: Schedule the third required task and first optional task. Total time is 2 + 5 = 7.
Day 4: Schedule the fourth required task. Total time is 4.
There is no other arrangement of optional tasks for which more than 2 optional tasks can be scheduled in 4 days.
Therefore, the maximum number of optional tasks that can be scheduled during these 4 days is 2.

Function Description
Complete the function getMaxTasksCompleted in the editor below.
getMaxTasksCompleted has the following parameters:
int dailyTimeLimit: the daily time limit for required tasks and optional tasks
int tasksRequired[n]: the duration of the required tasks
int tasksOptional[n]: the duration of the optional tasks

Returns
int: the maximum number of optional tasks that can be scheduled during these n days.

Constraints
1 ≤ n, dailyTimeLimit ≤ 2*10^5
1 ≤ tasksRequired[i], tasksOptional[i] ≤ dailyTimeLimit

Question 2:

The developers at Amazon are working on optimizing their database query times. There are n host servers, where the throughput of the ith host server is given by host_throughput[i].

These host servers are grouped into clusters of size three. The throughput of a cluster, denoted as cluster_throughput, is defined as the median of the host_throughput values of the three servers in the cluster. Each host server can be part of at most one cluster, and some servers may remain unused.

The total system throughput, called system_throughput, is the sum of the throughputs of all the clusters formed. The task is to find the maximum possible system_throughput.

Note: The median of a cluster of three host servers is the throughput of the 2nd server when the three throughputs are sorted in either ascending or descending order.

Example

n = 5
host_throughput = [2, 3, 4, 3, 4]

The maximum number of clusters that can be formed is 1, and two host servers will remain unused.

One possible cluster is to select the 1st, 3rd, and 5th host servers. The cluster_throughput of [2, 4, 4] will be 4 (the median value).

Thus, the system_throughput for all clusters will be 4.

Function Description
Complete the function getMaxThroughput in the editor below.
getMaxThroughput has the following parameter:
int host_throughput[n]: an array denoting the throughput of the host servers

Returns
long: the maximum system_throughput

Constraints
• 1 ≤ n ≤ 2*10^5
• 1 ≤ host_throughput[i] ≤ 10^9

Candidate's Approach

No approach provided.

Interviewer's Feedback

No feedback provided.