MediumPro challengePythonJavaScriptTypeScript

Memoize Async

AsyncPromisesPatterns

Implement memoizeAsync(fn) that memoizes an async function. Crucially,
concurrent calls with the same key must share the in-flight promise — not
launch separate requests.

solve(callGroups) simulates concurrent callers. Each group is an array of
argument lists that "arrive simultaneously". Return { results, calls }.

Sample tests

Test #1Two concurrent calls same args → 1 underlying call
Input: [[[[1,2],[1,2]]]]
Output: {"calls":1,"results":[[3,3]]}
Test #2Two batches, 3 unique args total
Input: [[[[1],[2]],[[1],[3]]]]
Output: {"calls":3,"results":[[1,2],[1,3]]}
Test #3Single call
Input: [[[[5]]]]
Output: {"calls":1,"results":[[5]]}
Test #4Three concurrent calls, two unique
Input: [[[[1,2],[3,4],[1,2]]]]
Output: {"calls":2,"results":[[3,7,3]]}
Test #5Same args across two sequential batches → still only 1 call
Input: [[[[10]],[[10]]]]
Output: {"calls":1,"results":[[10],[10]]}