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

Recursively Expanded Shell Command Counts

Hudson River Trading logoHudson River Trading● EasyNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Hudson River Trading new grad online assessment. The report does not give the three command labels, the output order, or the limits on the numbers. Our version is about 92% the same as the reported question.

You are given a command history. Every entry is one of the base commands cp, ls, and mv, or a history reference of the form !index.

Each index is one-based, refers to an earlier entry, and executes the command represented by that entry. A reference may point to another reference, so resolve references recursively.

Return the total execution counts in the order [cp, ls, mv], counting both direct executions and executions reached through references.

Function

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

Examples

Example 1

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

Entries 1, 3, and 4 execute ls. The direct cp and mv entries execute once each.

Example 2

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

Both references ultimately resolve to cp, so all three entries execute that command.

Example 3

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

The final reference points to entry 4, which resolves to ls. The totals are one cp, three ls executions, and two mv executions.

Constraints

  • 1 <= history.length <= 10^5.
  • Every entry is cp, ls, mv, or !index.
  • Every referenced index is between 1 and the current entry's one-based position minus 1.

More Hudson River Trading Online Assessment questions

  • Count Palindrome Addition ChoicesOA · Seen Nov 2026
  • Count Multiples of Three with Two SevensOA · Seen Oct 2026
  • Rotate Matrix Regions Around the DiagonalsOA · Seen Oct 2026
  • Maximum Diamond SumOA · Seen Oct 2026
  • Smallest Most-Lit Street PositionOA · Seen Oct 2026
  • Rearrange String by Alternating EndsOA · Seen Sep 2026
  • Most Items Within Budget from a Start IndexOA · Seen Sep 2026
  • Count Fancy NumbersOA · Seen Sep 2026
  • Count Sawtooth SubarraysOA · Seen Aug 2026
  • Backtick Identifier ConverterOA · Seen Jun 2026

Similar questions at other companies

  • Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
  • Book Reading EveningsGoogle · OAGoogle interview questions
  • Basic Item DiscountsPalantir · OAPalantir interview questions
  • Wind-Blown Leaves Remaining in a GridAbridge · OAAbridge interview questions
  • Lift Total TravelInfosys · OAInfosys interview questions
  • Shell Command Counts with History ReferencesTikTok · OATikTok interview questions
  • Count Dropped RequestsJP Morgan Chase · OAJP Morgan Chase interview questions
  • Diagonal Bounce TraversalAutodesk · OAAutodesk interview questions
  • First Value Below Both NeighborsCapital One · OACapital One interview questions
  • REST API: Highest International StudentsRippling · OARippling interview questions

Hudson River Trading interview experiences

  • Hudson River Trading Quant Video Interview: 1 Experience
  • HRT SWE Intern and Onsites: 34 Experiences (Part 2 of 2)
  • HRT Python Track Interviews: 64 Experiences (Part 1 of 2)
  • HRT New Grad Python Track Interviews: 9 Experiences
All Hudson River Trading interview questionsSee Hudson River Trading hiring insights
Saved
class Solution {
    public int[] countShellCommands(String[] history) {
        // Write your code here.
    }
}
Checking account…