Prototype: ChooseSpot(spots []Spot,kind string) (*string,error) selects the smallest compatible kind, then smallest ID, or nil. All spots are free. IDs nonempty and unique; kinds exactly motorcycle, car, van in that rank order. Validate every spot and request; preserve input.

Final: NewParkingLot(spots) (*ParkingLot,error) copies validated inventory (empty allowed). Park(vehicle,kind) (*Ticket,error) validates nonempty vehicle/kind and rejects an already active vehicle with error, even if capacity is exhausted. No free compatible spot returns nil without error. Ticket IDs start at 1 and advance only on success. Release(id) *Ticket frees an active integer ticket once, nil otherwise. ActiveTickets() []Ticket sorts by numeric ticket ID; AvailableSpots() []Spot sorts rank then ID. Released vehicles may park again; released ticket IDs remain inactive.

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.