Uplink Credit Auction
Problem
Several field teams share one limited satellite uplink slot. They bid from their communication-credit budgets before a fixed logical closing tick. Design UplinkCreditRound to accept on-time bids and identify the highest accepted bid after the auction closes.
Requirements
- Empty start. A new round stores its closing tick and starts with no accepted offers.
- Early offer. A bid before the closing tick stores the team's credits and returns
true. - Late offer. A bid at or after the closing tick leaves all accepted bids unchanged and returns
false. - Acceptance lookup. Looking up a team leaves all accepted bids unchanged and returns whether that team has an accepted bid.
- Winner. Choosing the winner leaves all accepted bids unchanged and returns the team ID with the greatest stored credits.
API
| Signature | Returns | Behavior |
|---|---|---|
UplinkCreditRound(closeTick: integer) | A new UplinkCreditRound | Creates an empty round with the supplied closing tick. |
offer(teamId: string, credits: integer, atTick: integer) | boolean | Accepts an early offer or rejects a late offer. |
hasOffer(teamId: string) | boolean | Reports whether the team has an accepted offer. |
winner(atTick: integer) | string | Returns the team with the greatest accepted credits. |
Examples
Given UplinkCreditRound(10):
| Call | Result |
|---|---|
offer("RIDGE", 40, 2) | true |
offer("LAKE", 70, 8) | true |
offer("SUMMIT", 90, 10) | false |
hasOffer("SUMMIT") | false |
winner(10) | "LAKE" |
Constraints
closeTickis between 1 and 100, inclusive.atTickis between 0 and 100, inclusive, and offer ticks are nondecreasing.creditsis between 1 and 1000, inclusive.- Team IDs match
[A-Za-z0-9_-]{1,24}. - Each team ID and credit amount appears in at most one
offercall. - A testcase contains at most 12 offers and 30 public method calls.
Notes
All calls are valid. winner is called at or after the closing tick after at least one accepted offer. Equal-credit ties, replacement offers, wall-clock time, and concurrency are outside the contract.