Prototype: Prototype(source []byte,ranges [][2]int) ([][]byte,error) returns one owned copy of each half-open [left,right) range, in order. Solve same API with every result's capacity exactly its length, including nonnil empty ranges. Validate 0<=left<=right<=len(source); any invalid range returns nil/error, preserving source/ranges. Outer successful output nonnil even empty. Overlapping ranges must not alias one another or input. Final O(total copied bytes + number of ranges).

Also final: TrimPointers(items []*Payload,keep int) ([]*Payload,error) requires 0<=keep<=len(items), validates before mutation, clears every original slot at index>=keep to nil, and returns the original prefix (same retained pointer identities) with len=cap=keep. This function deliberately mutates caller-owned tail slots. Retained Payload data is borrowed, not deep-copied. Nil items with keep=0 may return nil. Invalid keep returns nil/error with every pointer unchanged. No runtime.GC calls or timing assumptions are needed.

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.