Tap here to switch tabs
Problem
Submissions

Problem: Furthest Building You Can Reach

med
30 min
Try to solve the Furthest Building You Can Reach problem.

Statement

You are given an integer array heights where heights[i] is the height of building i. You start at building 00 and want to move to building i + 1 from building i for increasing i.

If heights[i + 1] <= heights[i], you can move to the next building without spending any resources. If heights[i + 1] > heights[i], you must cover the height difference heights[i + 1] - heights[i] by using either:
a number of bricks equal to that difference, or
one of your ladders.

Return the index of the furthest building you can reach.

Constraints:

  • 11 \leq heights.length 105\leq 10^5

  • 11 \leq heights[i] 106\leq 10^6

  • 00 \leq bricks 109\leq 10^9

  • 00 \leq ladders \leq heights.length

Unlock AI-Powered LearningUpgrade to smarter learning with instant explanations of Ask Agent, Personalized Interview Prep, Real-World Projects, 3 AI Mock Interviews per month, and Personalized Paths
Tap here to switch tabs
Problem
Submissions

Problem: Furthest Building You Can Reach

med
30 min
Try to solve the Furthest Building You Can Reach problem.

Statement

You are given an integer array heights where heights[i] is the height of building i. You start at building 00 and want to move to building i + 1 from building i for increasing i.

If heights[i + 1] <= heights[i], you can move to the next building without spending any resources. If heights[i + 1] > heights[i], you must cover the height difference heights[i + 1] - heights[i] by using either:
a number of bricks equal to that difference, or
one of your ladders.

Return the index of the furthest building you can reach.

Constraints:

  • 11 \leq heights.length 105\leq 10^5

  • 11 \leq heights[i] 106\leq 10^6

  • 00 \leq bricks 109\leq 10^9

  • 00 \leq ladders \leq heights.length

Unlock AI-Powered LearningUpgrade to smarter learning with instant explanations of Ask Agent, Personalized Interview Prep, Real-World Projects, 3 AI Mock Interviews per month, and Personalized Paths