Amazon OA SDE2

amazon logo
amazon
SDE II
April 4, 20254 reads

Summary

I completed the Amazon Online Assessment for an SDE2 role, which involved solving two distinct data structures and algorithms problems. The first problem focused on optimizing server selection based on efficiency and cost, and the second problem required determining customers who could achieve the highest total points in a reward tournament.

Full Experience

Q1: AWS provides a range of servers to meet their clients' deployment and computation needs. One AWS client wants to purchase servers to deploy their application.

You are given a description of n servers in form of two arrays, efficiency, and cost. Here efficiency is a hypothetical integer metric that represents the computational power of the server and cost is the number of AWS credits required to purchase the server. For simplicity, the servers have cost = 1 or cost = 2. Find the minimum possible total cost to purchase a set of servers with the total sum of efficiency greater than or equal to a given integer k.

If it is not possible to get a total efficiency of greater than or equal to k, report -1 as the answer.

Note: A server can only be purchased once.

Example

Consider the following four servers:

efficiency = [4, 4, 6, 7] cost = [1, 1, 2, 2] k=7

if we choose server indices [0,1] then cost is 1+1=2 which is minimum and efficiency is 4+4=8 which is greater than k

if we choose server indices [0,2] cost = 1+2=3, efficiency = 4+6=10

if we choose [1,2] cost is 1+2=3 and efficiency = 4+6=10 and so on. but we see that cost=2 which have indices[0,1] is minimum which satisfies the criteria of efficiency > k(=7)


Q2:

Amazon Shopping is running a reward collection event for its customers. There are in customers and the customer has collected InitialRewards[i] points so far.

One final tournament is to take place where the winner will be awarded n points, the runner-up will be awarded n -1 points, the customer in third place will get n - 2 points, and so on until the one in last place gets 1 point.

Given an integer array initialRewards of length n, representing the initial reward points of the customer initially before the final tournament.

Find the number of customers i(1 <= i <= n ) such that, if the ith customer wins the final tournament, le, they would have the highest total points.

Note: The total points for a customer are calculated as the sum of their initialRewards points and the points they would receive from the final tournament (with the winner receiving n points).

Example n = 3 InitialRewards = [1, 3, 4]

Let's analyze for each customer if they win the final tournament, would they have the highest total points or not:

If the 1st customer wins the final tournament, their total points would be: 1 + 3 = 4 but this is not the highest possible points in this case. For example, if the 3rd customer with an initial reward of 4 comes 2nd, then they would achieve a total of: 4+2=6 points which is the higher than 1st customer points

If the 2nd customer wins the final tournament, their total points would be: 3+3=6. and this is the highest total points in this case Even if the 3rd customer with an initial reward of 4 comes 2nd then they would achieve a total of 4+2-6 points which is not greater than 2nd customer points.

If the 3rd customer wins the final tournament, their total points would be: 4 + 3 = 7 and this is the highest total points, as there are no other customers that can achieve the total point of 7 in this case.

Thus, the customers 2 and 3 are the ones such that, if they win the final tournament they would have the highest total points. Hence, the answer is 2

Interview Questions (2)

Q1
Minimum Cost to Achieve Target Efficiency with Servers
Data Structures & Algorithms

AWS provides a range of servers to meet their clients' deployment and computation needs. One AWS client wants to purchase servers to deploy their application.

You are given a description of n servers in form of two arrays, efficiency, and cost. Here efficiency is a hypothetical integer metric that represents the computational power of the server and cost is the number of AWS credits required to purchase the server. For simplicity, the servers have cost = 1 or cost = 2. Find the minimum possible total cost to purchase a set of servers with the total sum of efficiency greater than or equal to a given integer k.

If it is not possible to get a total efficiency of greater than or equal to k, report -1 as the answer.

Note: A server can only be purchased once.

Example

Consider the following four servers:

efficiency = [4, 4, 6, 7] cost = [1, 1, 2, 2] k=7

if we choose server indices [0,1] then cost is 1+1=2 which is minimum and efficiency is 4+4=8 which is greater than k

if we choose server indices [0,2] cost = 1+2=3, efficiency = 4+6=10

if we choose [1,2] cost is 1+2=3 and efficiency = 4+6=10 and so on. but we see that cost=2 which have indices[0,1] is minimum which satisfies the criteria of efficiency > k(=7)

Q2
Customer Reward Tournament: Determine Potential Top Earners
Data Structures & Algorithms

Amazon Shopping is running a reward collection event for its customers. There are in customers and the customer has collected InitialRewards[i] points so far.

One final tournament is to take place where the winner will be awarded n points, the runner-up will be awarded n -1 points, the customer in third place will get n - 2 points, and so on until the one in last place gets 1 point.

Given an integer array initialRewards of length n, representing the initial reward points of the customer initially before the final tournament.

Find the number of customers i(1 <= i <= n ) such that, if the ith customer wins the final tournament, le, they would have the highest total points.

Note: The total points for a customer are calculated as the sum of their initialRewards points and the points they would receive from the final tournament (with the winner receiving n points).

Example n = 3 InitialRewards = [1, 3, 4]

Let's analyze for each customer if they win the final tournament, would they have the highest total points or not:

If the 1st customer wins the final tournament, their total points would be: 1 + 3 = 4 but this is not the highest possible points in this case. For example, if the 3rd customer with an initial reward of 4 comes 2nd, then they would achieve a total of: 4+2=6 points which is the higher than 1st customer points

If the 2nd customer wins the final tournament, their total points would be: 3+3=6. and this is the highest total points in this case Even if the 3rd customer with an initial reward of 4 comes 2nd then they would achieve a total of 4+2-6 points which is not greater than 2nd customer points.

If the 3rd customer wins the final tournament, their total points would be: 4 + 3 = 7 and this is the highest total points, as there are no other customers that can achieve the total point of 7 in this case.

Thus, the customers 2 and 3 are the ones such that, if they win the final tournament they would have the highest total points. Hence, the answer is 2

Discussion (0)

Share your thoughts and ask questions

Join the Discussion

Sign in with Google to share your thoughts and ask questions

No comments yet

Be the first to share your thoughts and start the discussion!