Shortest Agent Trace Window Covering Every Required Tool Call

Last updated: November 29, 2026

Quick Overview

Given the ordered list of tool names an agent invoked during a task and a multiset of required tools, return the inclusive start and end indices of the shortest contiguous span that contains every required tool at least as many times as required, or None.

OpenAI
Coding & Algorithms
Software Engineer
OpenAI
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Given the ordered list of tool names an agent invoked during a task and a multiset of required tools, return the inclusive start and end indices of the shortest contiguous span that contains every required tool at least as many times as required, or None.

Agent products like ChatGPT's agent mode produce long tool-call traces, and evaluators often need the tightest span where the agent did the work that matters. The question is a minimum covering window in disguise; OpenAI interviewers check correct multiplicity handling, the invariant behind shrinking the window, and a linear-time argument.

What the Interviewer Expects
  • Count required tools with multiplicity
  • Track a single 'missing' counter instead of comparing whole maps each step
  • Shrink from the left while the window remains valid
  • Return the earliest window on ties and say so
  • Prove each index enters and leaves the window once
Key Topics to Cover
sliding window
two pointers
hash counting
multiset coverage
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Required tools must appear in a given order: how does the solution change?
  • The trace is a stream and you can only keep O(k) memory for k distinct required tools: is that possible?
  • Return all minimal windows, not just one.
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Input: events, a list of tool names, and required, a list that may contain duplicates.
  • Output: (start, end) inclusive for the shortest valid window, earliest on ties; None if impossible. -...
High-Level Design

Maintain counts have for required tools inside the window [left, right] and a counter missing equal to how many required occurrences are still unsatisfied. Extend right; when an added tool is ...


Submit Your Answer
Markdown supported