Panda Guru LogoPanda
Guru

Amazon Interview Question - Tasks That Software Solve Given Task Difficulties & Software’s Abilities

Round 1

Questions: To evaluate advanced AI software at Amazon, we have q different programs set to undergo testing on n problems. Each problem has its own difficulty level difficulty[i] and a score tied to its complexity. Each AI program also comes with a specific ability level denoted by ability[i].

In practical terms, as software encounters each problem, it checks if its ability is sufficient to solve it. If the ability meets or exceeds the difficulty level, the program successfully solves the problem, earning a score equal to the problem's complexity. The program then moves on to the next problem. If the ability falls short, the evaluation for that problem concludes.

Formally, given two arrays: one array ability of size q, representing the ability level of all AI software, and another array difficulty of size n, representing the difficulty level of the problems.

Figure out the total score achieved by each of the q AI programs. It's important to note that if a program can't solve any problems, its score is zero.

Example 1

q = 2 ability = [2, 3] n = 4 difficulty = [2, 1, 3, 1]

Output = [3, 7]

Example 2

ability = [5, 1, 4] difficulty = [4, 1, 2, 5, 1]

Output = [13, 0, 7]

def calculate_scores(ability, difficulty): total_scores = [] memo = {} for ab in ability: if ab in memo: total_scores.append(memo[ab]) continue score = 0 for diff in difficulty: if ab >= diff: # Ability can solve the problem score += diff # Add the difficulty as the score else: break # Stop evaluating further problems memo[ab] = score total_scores.append(score) return total_scores
Candidate's Approach

I was able to solve it using the brute force solution which is O(N^2). However, I failed a few test cases and was unable to figure out how to optimize it further.

Interviewer's Feedback

No feedback provided.