FastPrepConcurrent Volley Shot

Concurrent Volley Shot

Temporal logoTemporal● MediumFULLTIMEPHONE SCREEN
Learn

Problem statement

A production shot(index) call may take between one and ten seconds and returns a boolean. All shots must start concurrently, and volleyShot completes with true as soon as any shot returns true; it returns false only after every shot has returned false.

For this deterministic judge adapter, latencies[i] is the completion time of shot i and results[i] is its returned value. Process completions in increasing latency order, breaking ties by smaller index, and return the volley result.

Function

volleyShot(latencies: int[], results: boolean[]) → boolean

Examples

Example 1

latencies = [9000,1000,5000]results = [true,false,true]return = true

The 1-second false completes first; the 5-second true completes the volley.

Example 2

latencies = [1000,2000,3000]results = [false,false,false]return = false

All shots finish false.

Example 3

latencies = [7000]results = [true]return = true

The only shot succeeds.

Constraints

  • 1 <= latencies.length == results.length <= 100000.
  • 1 <= latencies[i] <= 10000 milliseconds.

More Temporal problems

See Temporal hiring insights
public boolean volleyShot(int[] latencies, boolean[] results) {
    // Write your code here.
}
latencies[9000,1000,5000]
results[true,false,true]
expectedtrue
Checking account…