Panda Guru LogoPanda
Guru

Amazon | OA

Round 1

Questions: In managing tasks at an analytics platform, the goal is to efficiently schedule both primary and secondary tasks within specified time constraints.

There are n primary tasks and n secondary tasks. Two arrays, primary and secondary, provide information on task hours, where primary[i] represents the duration in hours of the ith primary task, and secondary[i] represents the duration in hours of the ith secondary task.

Each day on the platform has a time limit denoted as limit hours. One primary task must be scheduled each day. If time remains after the primary task, you can choose to schedule at most one secondary task on that day. It's essential to ensure that the total hours do not exceed the specified limit hours.

Determine the maximum number of secondary tasks that can be scheduled during these n days while adhering to the given constraints.

Example: limit = 7 primary = [4, 5, 2, 4] secondary = [5, 6, 3, 4]

One of the optimal scheduling can be:

There is no other arrangement of secondary tasks for which more than 2 secondary tasks can be scheduled in 4 days.

def get_freq(arr): freq = dict() for a in arr: freq[a] = freq.get(a, 0) + 1 return freq def max_secondary_tasks(limit, primary, secondary): secondary_freq = get_freq(secondary) count = 0 for p in primary: if p <= limit: if limit - p in secondary_freq and secondary_freq[limit - p] > 0: count += 1 secondary_freq[limit - p] -= 1 return count
Candidate's Approach

The candidate implemented a frequency dictionary to count occurrences of secondary tasks. For each primary task, they checked if the remaining time (after scheduling the primary task) could accommodate a secondary task. If so, they incremented the count of scheduled secondary tasks and updated the frequency dictionary accordingly.

Interviewer's Feedback

No feedback provided.