Problem, as an interviewer would state it: "Build a search-as-you-type controller: debounce the input, fire a real API request, and correctly handle the case where an EARLIER request resolves AFTER a LATER one — the UI must always show the result matching the user's most recent input, not whichever request happens to finish first."
Examples:
controller.search("reactjs"); // a slow request
controller.search("react"); // a fast request, made moments later
// even if "reactjs" resolves AFTER "react" does, the displayed result is for "react"
Clarifying questions expected:
- Is debouncing alone (only firing the LAST call in a burst) enough, or is a separate race-condition guard also needed?
- Should a discarded, stale response still be silently ignored, or surfaced somehow (e.g., logged)?
- Would using AbortController to genuinely CANCEL the stale network request be preferable to just ignoring its result?
Code / implementation expected: Yes — real, direct proof with a deliberately adversarial timing setup where the earlier request is slower and the later request is faster.