Problemtimed marketplace auctions

Session: Sign in to solve

Solution.txt

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

SignatureReturnsBehavior
UplinkCreditRound(closeTick: integer)A new UplinkCreditRoundCreates an empty round with the supplied closing tick.
offer(teamId: string, credits: integer, atTick: integer)booleanAccepts an early offer or rejects a late offer.
hasOffer(teamId: string)booleanReports whether the team has an accepted offer.
winner(atTick: integer)stringReturns the team with the greatest accepted credits.

Examples

Given UplinkCreditRound(10):

CallResult
offer("RIDGE", 40, 2)true
offer("LAKE", 70, 8)true
offer("SUMMIT", 90, 10)false
hasOffer("SUMMIT")false
winner(10)"LAKE"

Constraints

  • closeTick is between 1 and 100, inclusive.
  • atTick is between 0 and 100, inclusive, and offer ticks are nondecreasing.
  • credits is 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 offer call.
  • 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.

PRIVATE WORKSPACE

Checking your session…

The statement is public. The editor, editorial, submissions, and saved work are private.