Problem · Array

Debugger Breakpoint Actions

Learn this problem
EasyTiktok logoTiktokINTERNOA
See Tiktok hiring insights

Problem statement

A debugger starts on line 1 of a code snippet whose final line is codeLength. The sorted array breakpoints contains the unique line numbers that have breakpoints.

Process the strings in actions in order:

  • "next" moves the debugger forward by exactly one line.
  • "continue" moves the debugger to the first breakpoint strictly after its current line.

Every action is valid: "next" is never used on the final line, and a later breakpoint always exists for "continue".

Return the line on which the debugger stops after every action has been processed.

Function

debuggerFinalLine(codeLength: int, breakpoints: int[], actions: String[]) → int

Examples

Example 1

codeLength = 55breakpoints = [2,5,21,44]actions = ["next","next","continue","next","next"]return = 7

The two "next" actions move from line 1 to line 3. The next breakpoint after line 3 is line 5, and the final two actions move to line 7.

Example 2

codeLength = 10breakpoints = [4,8]actions = ["continue","next","continue"]return = 8

The debugger continues to line 4, advances to line 5, and then continues to line 8.

Example 3

codeLength = 6breakpoints = [2,4,6]actions = ["next","continue","next"]return = 5

The debugger moves to line 2, continues to the next breakpoint on line 4, and advances once to line 5.

Constraints

  • codeLength >= 1
  • breakpoints is sorted in strictly increasing order.
  • 1 <= breakpoints[i] <= codeLength
  • Every action is either "next" or "continue".
  • A "next" action is never performed on line codeLength.
  • For every "continue" action, a breakpoint exists strictly after the current line.

More Tiktok problems

drafts saved locally
public int debuggerFinalLine(int codeLength, int[] breakpoints, String[] actions) {
    // Write your code here.
}
codeLength55
breakpoints[2,5,21,44]
actions["next","next","continue","next","next"]
expected7
checking account