FastPrepPredict Forked Program Output
Problems/Predict Forked Program Output

Predict Forked Program Output

Squarepoint Capital logoSquarepoint Capital● EasyNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Squarepoint Capital new-grad phone screen. The report describes a question about the output of fork, but it does not keep the code. We chose the loop, the assumption that every fork succeeds, the final print, the limits, and the array of lines that you return. Our version is about 40% the same as the reported question.

Predict the complete output of a small process-creation program. For this exercise, assume the program starts with one process and runs this pseudocode:

repeat forkCount times:
    fork()
printLine(token)

Each fork() succeeds. It creates one child that continues immediately after that call, just as its parent does. Every process completes the remaining loop iterations, prints exactly one line, and exits. There is no output before the final print and no inherited buffered output.

Return a string array containing every printed line. All lines contain the same token, so process scheduling cannot change the returned value. Simulate the output; do not create real operating-system processes.

Function

predictForkOutput(forkCount: int, token: String) → String[]

Examples

Example 1

forkCount = 0token = "ready"return = ["ready"]

With no fork calls, the initial process alone prints one line.

Example 2

forkCount = 2token = "go"return = ["go","go","go","go"]

After the first fork there are two processes. Each forks once more, giving four processes and four go lines.

Example 3

forkCount = 1token = "A7"return = ["A7","A7"]

The parent and its one child each print A7 once.

Constraints

  • 0 <= forkCount <= 10.
  • 1 <= token.length <= 8.
  • Every character of token is an English letter or digit.

More Squarepoint Capital Phone Screen questions

  • Newton Square Root to a Guaranteed TolerancePHONE SCREEN · Seen Nov 2026
  • Probability of Consecutive HeadsPHONE SCREEN · Seen Nov 2026
  • Three Points in a Semicircle: Monte Carlo EstimatePHONE SCREEN · Seen Nov 2026
  • Combine Two Index SequencesPHONE SCREEN · Seen Aug 2026
  • Parse, Normalize, and Combine PolynomialsPHONE SCREEN · Seen Aug 2026
  • Sorted Insertion SnapshotsPHONE SCREEN · Seen Aug 2026
  • Strong and Weak Reference LifecyclePHONE SCREEN · Seen Aug 2026
  • Target Sum Across Two Sorted ArraysPHONE SCREEN · Seen Aug 2026
  • Classify Heap Addresses from a Memory SnapshotPHONE SCREEN · Seen Nov 2025
  • Fixed Worker Pool with a Shared QueuePHONE SCREEN · Seen Nov 2025

Similar questions at other companies

  • Automation Pipeline, Part 1: Single WorkerPlaid · PHONE SCREENPlaid interview questions
  • Search and Format ContactsAdyen · PHONE SCREENAdyen interview questions
  • Subtract Two Large Number StringsStackAdapt · PHONE SCREENStackAdapt interview questions
  • Array-Backed Set Without Library CollectionsOde with Anthropic · PHONE SCREEN
  • ID Allocator with Assign and ReleaseSnap Inc. · PHONE SCREENSnap Inc. interview questions
  • Portfolio Valuation, Part 1Stripe · PHONE SCREENStripe interview questions
  • Connect Four from the Last MoveSnowflake · PHONE SCREENSnowflake interview questions
  • Format a Signed Integer with CommasHudson River Trading · PHONE SCREENHudson River Trading interview questions
  • Fair Coin from a Biased CoinAnthropic · PHONE SCREENAnthropic interview questions
  • Paginate Retained Conversation HistorySierra · PHONE SCREENSierra interview questions

Interview reports that mention this question

  • Squarepoint Campus SDE Interviews: 7 Experiences (Part 2 of 2)

Squarepoint Capital interview experiences

  • Squarepoint Capital C++ and Python SWE Interviews: 7 Experiences
  • Squarepoint Capital New Grad SDE OA: 5 Experiences (Part 1 of 2)
All Squarepoint Capital interview questionsSee Squarepoint Capital hiring insights
Saved
class Solution {
    public String[] predictForkOutput(int forkCount, String token) {
        // write your code here
    }
}
Checking account…