The Maximum Building Height problem is a challenging math and array problem. You have n building slots arranged in a line (1 to n). Building 1 must have height 0. For any two adjacent buildings, their height difference cannot exceed 1. Additionally, you are given a list of restrictions: (id, maxHeight) which limits the height of specific buildings.
The goal is to find the maximum possible height any building can reach while satisfying all conditions.
Companies like Dataminr use this hard-level question to test:
This problem uses Constraint Propagation and Sorting.
height[i] = min(height[i], height[i-1] + gap)).height[i] = min(height[i], height[i+1] + gap)).(id1, h1) and (id2, h2), the maximum height reached between them is (h1 + h2 + (id2 - id1)) / 2.Buildings 1 to 10. Restriction: Building 10 must be height 3.
0 + 9 = 9. But restriction says 3. So min(9, 3) = 3.9 - 3 = 6.3 (base) + 3 (extra) = 6. Or use formula: (0 + 3 + 9) / 2 = 6.When dealing with "maximum possible" values subject to "slope" or "difference" constraints, always think about how restrictions propagate in both directions. The "left-pass, right-pass" strategy is a powerful tool for these types of grid or linear array problems.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Minimum Moves to Equal Array Elements II | Medium | Solve | |
| Maximum Product of Three Numbers | Easy | Solve | |
| Type of Triangle | Easy | Solve | |
| Allocate Mailboxes | Hard | Solve | |
| Best Meeting Point | Hard | Solve |