By Tanmay Ahuja
To find out the possible minimum difference of the height of shortest and longest towers after modifying each tower in C++.
In this project, I have minimized the difference between the maximum and the minimum height by incrementing or decrementing with the given factor k.
The approach used by me is:
1)First thing that I do is sorting the heights.
2)Now as I keep on traversing through the array I keep on checking the maximum and the minimum and their difference after both incrementing and decrementing them by the factor of k.
3)And Finally I print the minimum difference.
The image below shows the output of the project:
In this output we can see for an array 1 5 7 11 12 the minimum difference after incrementing/decrementing by 2 is 7.
Submitted by Tanmay Ahuja (tanmay140)
Download packets of source code on Coders Packet
Comments