FastPrepRecursively Expanded Shell Command Counts

Recursively Expanded Shell Command Counts

ZipRecruiter logoZipRecruiter● MediumNEW GRADOA
Learn

Problem statement

Every history entry is cp, ls, mv, or !index, where index is one-based from the session start and refers to an earlier entry.

A reference recursively executes the referenced entry. Return counts in [cp, ls, mv] order, counting direct and referenced executions.

Function

countShellCommands(history: String[]) → int[]

Examples

Example 1

history = ["ls","cp","!1","!3","mv"]return = [1,3,1]

Entries 1, 3, and 4 all execute ls.

Example 2

history = ["cp","!1","!2"]return = [3,0,0]

Both references recursively resolve to cp.

Constraints

  • 1 <= history.length <= 100000

More ZipRecruiter problems

See ZipRecruiter hiring insights
public int[] countShellCommands(String[] history) {
    // Write your code here.
}
history["ls","cp","!1","!3","mv"]
expected[1,3,1]
Checking account…