Concurrent Volley Shot
Updated
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.
In this practice version, 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[]) → booleanExamples
Example 1
latencies = [9000,1000,5000]results = [true,false,true]return = trueThe 1-second false completes first; the 5-second true completes the volley.
Example 2
latencies = [1000,2000,3000]results = [false,false,false]return = falseAll shots finish false.
Example 3
latencies = [7000]results = [true]return = trueThe only shot succeeds.
Constraints
1 <= latencies.length == results.length <= 100000.1 <= latencies[i] <= 10000milliseconds.
More Temporal interview questions
Similar questions at other companies
- Top K With a Deterministically Noisy Comparator (MLE)Mercor · ONSITE INTERVIEWMercor interview questions
- Mutual-Friend RecommendationsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
- Filter, Sort, and Deduplicate Scheduled TasksRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
- Merge Sorted Squares of Two ArraysWhatNot · PHONE SCREEN · ONSITE INTERVIEWWhatNot interview questions
- Top K Frequent ElementsAmazon · OA · PHONE SCREEN
- Merge Overlapping IntervalsAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
- Merge Weekday and Time IntervalsNextdoor · PHONE SCREENNextdoor interview questions
- Peak Chat Load Across AgentsCresta · PHONE SCREENCresta interview questions
- Longest Consecutive SequenceJP Morgan Chase · PHONE SCREENJP Morgan Chase interview questions
- Determine the Winner of Three-Card HandsOpenAI · PHONE SCREENOpenAI interview questions