Recursively Expanded Shell Command Counts
Updated
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 Online Assessment questions
- Four-Level Banking System with Scheduled PaymentsOA · Seen Oct 2026
- Count Three-Digit Numbers with Distinct DigitsOA · Seen Oct 2024
- Longest Frequency-Bounded SubarrayOA · Seen Oct 2024
- Minimum Changes to Draw a YOA · Seen Oct 2024
- Apply Binary State OperationsOA · Seen Sep 2024
- Simulate Orchard Rot SpreadOA · Seen Sep 2024
- Compare Odd- and Even-Index SumsOA · Seen Sep 2024
- Coordinate Removals with Column GravityOA · Seen Sep 2024
- Lexicographically Smallest End ReversalOA · Seen Sep 2024
- Count Case-Insensitive Key ChangesOA · Seen Sep 2024
Similar questions at other companies
- Query Words Within K PositionsPalantir · PHONE SCREENPalantir interview questions
- Word BreakAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Word BreakMoveworks · ONSITE INTERVIEWMoveworks interview questions
- Most Relevant Text SpanHebbia · PHONE SCREEN
- Word BreakBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Longest Common Contiguous User ActionsWayfair · PHONE SCREENWayfair interview questions
- Longest Common URL History RunDatadog · PHONE SCREENDatadog interview questions
- Find a String Within One Mismatch of AllBarclays · OABarclays interview questions
- Maximum Game Score with Fixed Forward JumpsStripe · OAStripe interview questions
- 0/1 KnapsackConfluent · OAConfluent interview questions