• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
May 07, 2024 |270 Views
SDE Sheet - Minimize the heights
  Share  1 Like
Description
Discussion

This video is part of the Greedy section under GFG SDE Sheet.

In this problem, we are given an array arr[] denoting heights of N towers and a positive integer K.

For each tower, you must perform exactly one of the following operations exactly once.

Increase the height of the tower by K
Decrease the height of the tower by K
Find out the minimum possible difference between the height of the shortest and tallest towers after you have modified each tower.

You can find a slight modification of the problem here.
Note: It is compulsory to increase or decrease the height by K for each tower. After the operation, the resultant array should not contain any negative integers.

Try it out before watching the implementation of the problem in the video. We recommend watching the video, even if you can solve the problem. You may discover something new. All the best!!!

Do check out:-
Article: https://www.geeksforgeeks.org/minimize-the-maximum-difference-between-the-heights/
Problem: https://www.geeksforgeeks.org/problems/minimize-the-heights3351/1
SDE Sheet Link: https://www.geeksforgeeks.org/sde-sheet-a-complete-guide-for-sde-preparation/