Add sentinel restrictions for the first and last buildings.
Sort the restrictions by building index.
Propagate the restrictions from left to right, updating the maximum height of each building based on the previous building's height and the distance between them.
Propagate the restrictions from right to left in a similar manner.
Iterate through each pair of adjacent restrictions and calculate the maximum possible height between them.
The maximum height is the maximum of all calculated heights.