FastPrepAdvance or Jump to the Next Special Line

Advance or Jump to the Next Special Line

ZipRecruiter logoZipRecruiter● EasyNEW GRADOA
Learn

Problem statement

Start at line 1. next increments the current line by one. continue jumps to the first sorted nextLine value strictly greater than the current line.

Return the final line. Every continue command is guaranteed to have a destination.

Function

navigateLines(nextLine: int[], commands: String[]) → int

Examples

Example 1

nextLine = [4,10]commands = ["next","continue","next"]return = 5

The path is 1 to 2 to 4 to 5.

Example 2

nextLine = [4,10]commands = ["continue","next","next"]return = 6

The path is 1 to 4 to 5 to 6.

Constraints

  • 0 <= nextLine.length,commands.length <= 100000

More ZipRecruiter problems

See ZipRecruiter hiring insights
public int navigateLines(int[] nextLine, String[] commands) {
    // Write your code here.
}
nextLine[4,10]
commands["next","continue","next"]
expected5
Checking account…