Panda Guru LogoPanda
Guru

Amazon Fungible OA

Round 1

Questions:

Question 1: Parcel Distribution Among Agents

You are given an array representing the number of parcels each delivery agent currently holds. Additionally, there are a certain number of extra parcels available that need to be distributed among the agents. The goal is to distribute these extra parcels such that the maximum number of parcels any agent holds after distribution is minimized.

Input:

Output:

e.g.

agents = [1, 5, 1, 7, 9] extraParcels = 25

answer = 10

Question 2: Array Peak Minimization

You are given an array of integers where the values first increase and then decrease. The task is to make the array non-decreasing by adding the minimum possible values to the elements. Specifically, for each element that is smaller than the one before it, you need to calculate how much you need to add to make it greater than or equal to the previous element.

Input:

Output:

e.g.

[3, 4, 1, 6, 2]

ans = 7 (3 + 4)

explanation -

3 4 1 6 2 3 4 4 9 5 (+3 applied to 1, 6, 2) 3 4 4 9 9 (+4 applied to 5)
Candidate's Approach

I was only able to pass 7/15 test-cases in both, despite being able to identify that both needed greedy approaches. I worked using a Min-Heap, Sorting, and Two-Pointer for the first one, but still couldn't resolve the TLE. The second one as well, I think I just confused myself.

Interviewer's Feedback

No feedback provided.