Furthest Building You Can Reach
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
You are walking along a row of buildings with heights heights[0..n-1], starting on building 0, and you move from building i to building i + 1 one step at a time.
If the next building is no taller than the current one, the step is free. Otherwise you must cover the climb d = heights[i+1] - heights[i] either with exactly d bricks or with one ladder. You have bricks bricks and ladders ladders in total, and each can be used only once.
Return the largest building index you can reach if you spend your resources optimally.
Examples
Constraints
- 1 <= heights.length <= 10^5
- 1 <= heights[i] <= 10^6
- 0 <= bricks <= 10^9
- 0 <= ladders <= heights.length
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.