Implement Concurrent Any-True Shot
Implement Concurrent Any-True Shot
You are tasked with implementing a function volleyShot(indices) that orchestrates multiple calls to a given shot(index) function. Each call to shot(index) is asynchronous and may take between 1 and 10 seconds to complete, returning a boolean value.
Requirements:
- Concurrent Execution: Start multiple
shotcalls concurrently for all providedindices. - Early True Termination: Return
Trueas soon as anyshotcall returnsTrue. - Late False Termination: Return
Falseonly after allshotcalls have completed and every single one returnedFalse. - Best-Effort Cancellation: If the final answer (
TrueorFalse) is already determined, do not keep waiting for slowershotcalls. Implement best-effort cancellation for any ongoing operations. - Empty Input: If the
indiceslist is empty,volleyShotshould immediately returnFalse.
Focus:
The primary focus of this problem is on demonstrating proficiency in concurrency management and implementing efficient early termination strategies.
AI interview prep
Core dilemma
Balancing the need for immediate responsiveness (returning True as soon as possible) with the requirement for complete task execution (waiting for all tasks to finish before returning False), all while efficiently managing concurrent resources and implementing best-effort cancellation.
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Implement Concurrent Any-True Shot
Implement Concurrent Any-True Shot
You are tasked with implementing a function volleyShot(indices) that orchestrates multiple calls to a given shot(index) function. Each call to shot(index) is asynchronous and may take between 1 and 10 seconds to complete, returning a boolean value.
Requirements:
- Concurrent Execution: Start multiple
shotcalls concurrently for all providedindices. - Early True Termination: Return
Trueas soon as anyshotcall returnsTrue. - Late False Termination: Return
Falseonly after allshotcalls have completed and every single one returnedFalse. - Best-Effort Cancellation: If the final answer (
TrueorFalse) is already determined, do not keep waiting for slowershotcalls. Implement best-effort cancellation for any ongoing operations. - Empty Input: If the
indiceslist is empty,volleyShotshould immediately returnFalse.
Focus:
The primary focus of this problem is on demonstrating proficiency in concurrency management and implementing efficient early termination strategies.