FastPrepRecursively Expanded Shell Command Counts
Problems/Recursively Expanded Shell Command Counts

Recursively Expanded Shell Command Counts

ZipRecruiter logoZipRecruiter● MediumNEW GRADOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Two ZipRecruiter new-grad OA reports preserve the base commands, recursive one-based history references, and output order. Recorded enrichment resolves a shorthand example by counting every actual direct or referenced execution.

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

ZipRecruiter interview experiences

  • ZipRecruiter SWE OA, Level Not Reported: 23 Experiences
  • ZipRecruiter SWE Intern OA Scores: 4 Experiences
  • ZipRecruiter SWE New Grad OA: 9 Experiences
All ZipRecruiter interview questionsSee ZipRecruiter hiring insights
Saved
class Solution {
    public int[] countShellCommands(String[] history) {
        // Write your code here.
    }

}
Checking account…