Recursively Expanded Shell Command Counts
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