MediumPro challengePythonJavaScriptTypeScript

Async Semaphore

Node.jsAsyncConcurrency

Implement a semaphore limiting concurrent async ops to max.

solve(max, durations) simulates each duration with setTimeout under
the semaphore. Returns total elapsed time (ms) across all tasks.

Sample tests

Test #14 tasks, max 2, 50ms each → ~100ms
Input: [2,[50,50,50,50]]
Output: 100
Test #2Serial: 3*30 = 90ms
Input: [1,[30,30,30]]
Output: 90
Test #3Single task
Input: [10,[40]]
Output: 40
Test #4All in parallel
Input: [3,[20,20,20]]
Output: 20
Test #52 in parallel
Input: [2,[50,50]]
Output: 50