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.
• You are given an array agents where each element represents the number of parcels an agent currently holds.
• There are extraParcels extra parcels that need to be distributed among the agents.
• You need to find a way to distribute the parcels so that the maximum number of parcels with any agent is as small as possible.
Input:
• agents (list of integers)
• extraParcels (integer)
Output:
• Return the minimized maximum number of parcels any agent holds after distribution.
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.
• You are given an array of integers where the values initially increase and then decrease.
• Your goal is to transform the array into a non-decreasing one by adding the minimum sum of values to the elements.
Input:
• arr (list of integers)
Output:
• Return the total sum of values that need to be added to make the array non-decreasing.
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)
Hey Everyone!
I just gave my Amazon SDEI Fungible OA. I have shared the questions that were asked.
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.
I wanted to ask - are these very standard issue questions? How easy are they supposed to be? How/Where should I be practicing to be able to easily solve these kinds of questions?
I have solved Graphs/DP/Arrays/Strings etc. in a topicwise fashion, but I suspect something is lacking in my understanding if I am not able to crack what looks like a trivial greedy question.
Any feedback is appreciated. I want to be better at this in two months time.