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.
- 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)
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.