12. Minimize the Heights II
β GFG solution to the Minimize the Heights II problem: find minimum difference between tallest and shortest towers after mandatory height modifications using greedy approach. π
π§© Problem Description
π Examples
Example 1
Input: k = 2, arr[] = [1, 5, 8, 10]
Output: 5
Explanation: The array can be modified as [1+k, 5-k, 8-k, 10-k] = [3, 3, 6, 8].
The difference between the largest and smallest is 8-3 = 5.Example 2
Input: k = 3, arr[] = [3, 9, 12, 16, 20]
Output: 11
Explanation: The array can be modified as [3+k, 9+k, 12-k, 16-k, 20-k] = [6, 12, 9, 13, 17].
The difference between the largest and smallest is 17-6 = 11.π Constraints
β
My Approach
Greedy Split-Point Strategy
π Time and Auxiliary Space Complexity
π§βπ» Code (C++)
β Code (Java)
π Code (Python)
π§ Contribution and Support
πVisitor Count
Last updated