Workspace/Coding labs
Loading progress

Bound asynchronous work and preserve ordering

Intermediate65 min

Implement async bounded_squares(values, limit). Validate a list of exact integers and a positive exact integer limit. Square every value using local asynchronous tasks that yield once with asyncio.sleep(0). Return (squares_in_input_order, peak_active). At most limit tasks may be active inside the work region. Empty input returns ([], 0). No network, subprocess, sleeps with real delays, or user input are needed.

Your task

  1. Complete the starter function using the contract above.
  2. Use the examples and visible tests to check normal inputs, boundaries, and rejected inputs.
  3. Run tests to record your result, then compare with the explained reference solution.

Examples

EXAMPLE 1

Inputawait bounded_squares([3, -2, 0], 2)

Output([9, 4, 0], 2)

The work overlaps but result order follows the input.
EXAMPLE 2

Inputawait bounded_squares([], 5)

Output([], 0)

No task enters the work region.
solution.pyPython 3.12