PIXELBANKv9.1.0
Menu

Deadline Remaining Before a Tool Call

Problem Statement

An agent has an overall deadline. Before each tool call, compute how much time is left, and whether there is enough to attempt a call that needs cost seconds.

Background

Given a deadline (absolute seconds), the current time now, and an estimated cost, the remaining budget is max(deadline - now, 0). A call should proceed only if remaining >= cost.

Your Task

Implement:

def deadline_check(deadline, now, cost):

Return a dict with "remaining" (float, clamped at 0) and "proceed" (bool).

Input Format

  • deadline (float), now (float), cost (float).

Output Format

  • A dict {"remaining": float, "proceed": bool}.

Sample

print(deadline_check(100.0, 90.0, 5.0))

Output:

{'remaining': 10.0, 'proceed': True}

Example:

Input:
print(deadline_check(100.0, 90.0, 5.0))
Output:
{'remaining': 10.0, 'proceed': True}
Reasoning:
  • Calculate the raw time difference between the absolute deadline and the current time to determine the theoretical budget: 100.0−90.0=10.0100.0 - 90.0 = 10.0.
  • Clamp this value at zero to ensure the remaining time is non-negative, which is necessary because negative time is not a valid budget: max⁡(10.0,0.0)=10.0\max(10.0, 0.0) = 10.0.
  • Compare the calculated remaining time against the estimated cost of the tool call to decide if it is safe to proceed: 10.0≥5.010.0 \ge 5.0 evaluates to True.
  • Combine these results into the required dictionary structure with the keys "remaining" and "proceed".
  • The final output is {'remaining': 10.0, 'proceed': True}

Constraints:

  • remaining = max(deadline - now, 0).
  • proceed = remaining >= cost.
  • Return remaining as a float.
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.
Deadline Remaining Before a Tool Call - Easy | PixelBank