FastPrepLowest-Bid Auction System

Lowest-Bid Auction System

Google logoGoogle● MediumFULLTIMEONSITE INTERVIEW

Problem statement

Build an auction system where the lowest bid is the best bid. Process a list of operations in order. operations[i] is the name of operation i, and args[i] holds its integer arguments.

  • "bid" with arguments [auctionId, amount]: place a bid of amount on auction auctionId. An auction opens the first time it receives a bid. A bid on an auction that was removed is ignored.
  • "lowest" with no arguments: report the lowest bid amount among all bids on auctions that have not been removed, or -1 if there is no such bid. This operation does not change anything.
  • "remove" with arguments [auctionId]: remove auction auctionId. Its bids stop counting, and every later bid on it is ignored. Removing an auction that has no bids or was already removed still marks it as removed and does nothing else.

Return an array with one value for each "lowest" operation, in order.

The problem statement continues
Pro

Examples

Example 1

operations = ["bid","bid","bid","lowest","remove","lowest","bid","lowest"]args = [[1,50],[2,30],[1,40],[],[2],[],[2,10],[]]return = [30,40,40]
  • After three bids, the amounts are 50 and 40 on auction 1 and 30 on auction 2, so the first query reports 30.
  • Removing auction 2 drops its bid, so the second query reports 40.
  • The bid of 10 on removed auction 2 is ignored, so the last query still reports 40.
FastPrep Pro
Reported in 1 Google interview this week

Unlock this recently reported problem

FastPrep Pro gives you full access to interview problems reported within the last week.

  • Full problem statement and constraints
  • 2 more worked examples, explained
  • Guided hints and editorial
  • Run your code on real test cases
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week
See Google hiring insights
CodePython 3
Run and Submit unlock with Pro
FastPrep Pro
Reported in 1 Google interview this week

Unlock this recently reported problem

FastPrep Pro gives you full access to interview problems reported within the last week.

  • Full problem statement and constraints
  • 2 more worked examples, explained
  • Guided hints and editorial
  • Run your code on real test cases
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week