Fixed Worker Pool with a Shared Queue
Updated
Problem statement
Implement a fixed worker pool using workers, a mutex-protected FIFO queue and an availability semaphore. Workers take jobs from the shared queue and report their results.
For this exercise, assume each input position is one job whose work is to square its integer value. Start exactly workerCount workers. Queue jobs in input order, execute each job exactly once, then stop the workers after all jobs have been dispatched. Wait for every worker to acknowledge completion before returning the squared values in original input order. Empty input returns an empty array.
The squaring job and finite batch interface are practice fixtures. Use actual workers and shared synchronization rather than a sequential event simulation. In JavaScript the synchronous adapter uses worker threads, shared memory and atomic semaphore/mutex operations; completion acknowledgement does not claim that the operating system has already destroyed each thread. The automated judge checks result values.
Function
runSquarePool(workerCount: int, values: int[]) → int[]Examples
Example 1
workerCount = 2values = [2,-3,0]return = [4,9,0]The jobs square to 4, 9 and 0. Worker completion order may vary, but result positions follow the original input.
Example 2
workerCount = 2values = []return = []There are no data jobs. Each worker receives a stop marker and acknowledges completion. Return an empty array.
Example 3
workerCount = 1values = [10000,-10000]return = [100000000,100000000]Both endpoint values square to 100000000. One worker processes both queued jobs before stopping.
Constraints
1 <= workerCount <= 2.0 <= values.length <= 1000.-10000 <= values[i] <= 10000.
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
- String Copy and Move LifecyclePHONE SCREEN · Seen Nov 2025
Similar questions at other companies
- Simulate a Queued Multi-Rule Rate LimiterSnowflake · PHONE SCREENSnowflake interview questions
- Modal Lock and Fair Modal LockOpenAI · PHONE SCREENOpenAI interview questions
- Sliding Window MaximumGroww · PHONE SCREEN
- Largest Value in Every Sliding WindowAdobe · PHONE SCREENAdobe interview questions
- Shortest Subarray with Sum at Least KGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
- Sliding Window MaximumBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Sliding Window MaximumNVIDIA · PHONE SCREENNVIDIA interview questions
- Shortest Subarray with Sum at Least KGoogle · PHONE SCREENGoogle interview questions
- Design Hit CounterCharta Health · PHONE SCREENCharta Health interview questions
- Constant-Time Weighted Pick with an Alias TableEtched · PHONE SCREEN