Leetcode Problem 1642. Furthest Building You Can Reach

1642. Furthest Building You Can Reach

Leetcode Solutions

Approach: Min-Heap

  1. Initialize a min-heap to keep track of the climbs where ladders are used.
  2. Iterate through the array of building heights.
  3. For each climb, if we have ladders left, use a ladder and add the climb to the min-heap.
  4. If we don't have ladders, compare the current climb with the smallest in the heap.
  5. If the current climb is larger, use a ladder for it and replace the smallest ladder climb with bricks.
  6. If the current climb is smaller or equal, use bricks for it.
  7. If at any point we do not have enough bricks to make the next climb, return the current index.
  8. If we finish iterating through the buildings, return the last index.
UML Thumbnail

Approach: Max-Heap

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Code Diffs Compare
Full Screen
Copy Answer Code
Loading...