25. Maximize Median After K Addition Operations
β GFG solution to the Maximize Median After K Addition Operations problem: find maximum possible median after performing at most k increment operations using binary search and greedy strategy. π
π§© Problem Description
π Examples
Example 1
Input: arr[] = [1, 3, 4, 5], k = 3
Output: 5
Explanation: We can add +2 to the second element and +1 to the third element to get the array [1, 5, 5, 5].
After sorting, the array remains [1, 5, 5, 5]. Since the length is even, the median is (5 + 5) / 2 = 5.Example 2
Input: arr[] = [1, 3, 6, 4, 2], k = 10
Output: 7
Explanation: After applying operations optimally, we can transform the array to [1, 3, 7, 7, 7] (one possible way).
Sorted array becomes [1, 3, 7, 7, 7]. Since the length is odd, the median is the middle element 7.π Constraints
β
My Approach
Binary Search + Greedy Validation
π Time and Auxiliary Space Complexity
π§βπ» Code (C++)
β Code (Java)
π Code (Python)
π§ Contribution and Support
πVisitor Count
Last updated