Leetcode Problem 1642. Furthest Building You Can Reach
1642. Furthest Building You Can Reach
AI Mock Interview
Leetcode Solutions
Approach: Min-Heap
Solution Idea
Algorithm Steps
Code Implementation
Complexity Analysis
Initialize a min-heap to keep track of the climbs where ladders are used.
Iterate through the array of building heights.
For each climb, if we have ladders left, use a ladder and add the climb to the min-heap.
If we don't have ladders, compare the current climb with the smallest in the heap.
If the current climb is larger, use a ladder for it and replace the smallest ladder climb with bricks.
If the current climb is smaller or equal, use bricks for it.
If at any point we do not have enough bricks to make the next climb, return the current index.
If we finish iterating through the buildings, return the last index.
Approach: Max-Heap
Ask Question
Programming Language
Purpose:
General Question
Debug My Code
image/screenshot of info
(optional)
[+]
Full Screen
Loading...
Get Answer
Suggested Answer
Answer
Code Diffs Compare
Full Screen
Copy Answer Code
Loading...