Maximize minimum after K decrements
Company: MathWorks
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: easy
Interview Round: Technical Screen
Quick Answer: This Coding & Algorithms question evaluates algorithmic problem-solving skills in array manipulation and constrained optimization, testing competency in reasoning about value distribution, large numeric bounds, and performance under tight complexity limits.
Constraints
- 1 <= len(A)
- K >= 0
Examples
Input: ([5, 1, 7], 3)
Expected Output: 1
Explanation: Decrement values above the minimum.
Input: ([1, 1], 1)
Expected Output: 0
Explanation: Once all values equal the minimum, one decrement lowers the minimum.
Input: ([4, 4, 4], 5)
Expected Output: 2
Explanation: Distribute decrements evenly after equalization.
Input: ([-1, 2], 4)
Expected Output: -2
Explanation: Handles negative values.
Hints
- First spend decrements on elements above the current minimum; only extra decrements force the minimum lower.