Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

End-to-End Debugger Simulation

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is End-to-End Debugger Simulation. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

For an HRT-style debugging trace, a program has executable lines numbered from 1 through total_lines. The debugger starts stopped at line 1. Given sorted breakpoint locations and a sequence of commands, simulate execution and return the final line where the debugger stops.

A next command advances execution by exactly one line. A continue command advances to the first breakpoint strictly greater than the current line. If no such breakpoint exists, it advances directly to total_lines. Once the debugger reaches total_lines, all later commands leave it there.

Breakpoints are unique and sorted in strictly increasing order.

Formal Specification

Implement final_debug_line(total_lines, breakpoints, actions):

  • total_lines: integer, the last executable line.
  • breakpoints: sorted list of integers identifying breakpoint lines.
  • actions: list containing only the strings "next" and "continue".
  • Return the final stopped line as an integer.

Constraints

  • 1 <= total_lines <= 10^9
  • 0 <= len(breakpoints) <= 10^6
  • 0 <= len(actions) <= 10^6
  • 1 <= breakpoints[i] <= total_lines
  • Breakpoints are strictly increasing
  • actions contains only "next" and "continue"

Function Signature

def final_debug_line(total_lines, breakpoints, actions):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output