Skip to content

Practice Maximum Building Height

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#1840
LeetCode Problem

Maximum Building Height

Problem Statement

Buildings 1 through n have nonnegative integer heights. Building 1 has height 0 and adjacent heights may differ by at most 1. Each [id,maxHeight] in restrictions imposes an additional upper bound for that building. Return the greatest possible height of the tallest building among arrangements obeying all bounds.

Source: Maximum Building Height on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
n = 5, restrictions = [[2,1],[4,1]]
Output
2

# Example 2

Input
n = 6, restrictions = []
Output
5

# Example 3

Input
n = 10, restrictions = [[5,3],[2,5],[7,4],[10,3]]
Output
5

Constraints

2 <= n <= 10^9
0 <= restrictions.length <= min(n - 1, 10^5)
2 <= idi <= n
idi is unique.
0 <= maxHeighti <= 10^9

Related LeetCode Problems

Practice more problems similar to Maximum Building Height.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.