Furthest Building You Can Reach

Medium · Heap & Priority Queue · about 20 minutes

Asked at Google, Amazon, Meta, Bloomberg.

You walk from building 0 to the right along heights. Moving to a building that is not taller is free. To climb to a taller building you use either one ladder or heights[i+1] - heights[i] bricks. Given bricks and ladders, return the furthest building index you can reach.

Related guides