Search⌘ K
AI Features

Solution: Furthest Building You Can Reach

C# solution for the Furthest Building You Can Reach problem using the Heaps pattern.

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] \leq 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: ...