Prototype: AllowRequest(recent []int,limit,window,now int) (Decision,error). Positive limit/window, nonnegative now; history nonnegative nondecreasing and <=now, duplicates valid. Filter timestamps strictly >now-window. Allow and append now only when filtered length <limit; retain overfull unexpired history on denial. Preserve input.

Final: NewSlidingWindowLimiter(limit,window) (*SlidingWindowLimiter,error) validates settings. Allow(client string,now int) (bool,error) requires nonempty client and nonnegative nondecreasing per-client time, including denied calls. Error preserves observed time/history. Valid calls expire old accepted timestamps, decide and advance observed time. Clients have unrelated clocks. History(client) ([]int,error) validates client and returns a fresh retained history relative to its most recent valid Allow; unseen valid client empty. History never advances time.

All identifiers and strings compare exactly and case-sensitively. Numeric inputs are typed int; booleans cannot be passed as amounts. Arithmetic and logical timestamps fit int. All supplied collection inputs that are retained must be copied. Every collection or pointer snapshot must be detached; separate service instances own independent state. A nil pointer or nil optional slice denotes absence, while an ordinary empty result collection is nonnil. Invalid calls leave state unchanged unless the contract explicitly accepts time and expires state on a valid unsuccessful call. The exported signatures in exercise.go are the API specification.

Edit exercise.go; retain the public types and signatures. prototype and final are separate stages. The executable tests recover panics as failures, report named checks, and exit nonzero on any failure. A successful run must execute at least one check. Tests use logical time or explicit synchronization where relevant.

Drag or use the arrow keys to resize. Home collapses the question; End collapses the editor. Enter or double-click resets the split.
Loading editor…
No results yet.

Complete the starter code, then run the checks.
Results and errors will appear here.