HardPythonJavaScriptTypeScript
asyncio.gather — Run Tasks Concurrently
PythonAsyncConcurrency
Implement solve(delays) that:
1. Creates one coroutine per item in delays — each coroutine waits delay seconds then returns delay * 10.
2. Runs all coroutines concurrently with asyncio.gather.
3. Returns the list of results in the same order as the input.
Examples
solve([0.1, 0.2, 0.05])→[1, 2, 0]*(delays × 10, rounded down)*solve([0.3])→[3]
Constraints
- Use
asyncio.gather— do not run coroutines sequentially. - Results must preserve input order (gather guarantees this).
- Total wall-clock time should be ≈ max(delays), not sum(delays).
The checker controls sleep completion to verify that every worker waits,
all workers start before any finishes, and results preserve input order.
In JavaScript / TypeScript — worker(delay) waits delay seconds with setTimeout, then returns Math.floor(delay * 10). Promise.all is the counterpart of asyncio.gather: concurrent, results in input order.
Sample tests
Test #1No tasks produces an empty result
Input: [[]]
Output: []
Test #2Three tasks, results in input order
Input: [[0.1,0.2,0.05]]
Output: [1,2,0]
Test #3Single task
Input: [[0.3]]
Output: [3]
Test #4Zero delays
Input: [[0,0]]
Output: [0,0]