FastPrepHighest Bid Campaign Matcher
Problems/Highest Bid Campaign Matcher

Highest Bid Campaign Matcher

StackAdapt logoStackAdapt● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported as the coding round of the virtual onsite in a StackAdapt interview loop for a full-time software engineering role. The task was a short written spec with two functions: one stores an ad campaign, and the other takes a bid request and returns the campaign with the top bid among those that fit the request on ad format and on the user's demographics. The candidate thought a hash map, a set and a priority queue would be enough to solve it. The other rounds of the loop are not part of this problem.

The report says nothing about the fields of a campaign or a request, ties, a request that nothing fits, or the order of the calls, so these choices are ours. One function gets all the operations as text and returns one answer per query, instead of a class with two methods. Each campaign has exactly one ad format, and demographics are plain tags. We assume a campaign fits a request when the formats are the same and every tag the campaign targets is among the request's tags, so a campaign with no tags fits any user. Bids are whole numbers. When the top bid is shared, the campaign inserted first wins, and a query that nothing fits returns NONE. A query sees only the campaigns inserted before it. Campaigns are never removed, since the report names only the two functions for storing and asking. The limits and all the examples are ours.

Our version is about 70% the same as the reported question.

Given a list of operations, store the campaign that each INSERT adds, and answer each QUERY with the id of the campaign that bids the most among the stored campaigns that match the request on ad format and on demographics. Return the answers in the order of the queries.

An insert looks like "INSERT id bid format tag1 tag2 ...". It adds a campaign with its own id, a whole-number bid, one ad format (such as video or banner) and 0 to 6 target demographic tags (such as female or age25to34). An insert has no answer.

A query looks like "QUERY format tag1 tag2 ...". It is a bid request for one ad slot of that format, shown to a user who has the 0 to 6 listed demographic tags.

A campaign matches a request when both of these hold:

  • its format is the same as the request's format, and
  • every one of its target tags is among the request's tags. The request may have other tags too, so a campaign with no target tags matches every request of its format.

Among the matching campaigns, the one with the highest bid wins. If several of them share that bid, the one inserted first wins. If no campaign matches, the answer is "NONE". A query sees only the campaigns inserted before it in the list.

Function

matchCampaigns(operations: String[]) → String[]

Examples

Example 1

operations = ["INSERT c1 300 video female age25to34","INSERT c2 500 video male","INSERT c3 200 banner","QUERY video female age25to34 toronto","QUERY banner male","QUERY video age25to34"]return = ["c1","c3","NONE"]

The first request is for video and has the tags female, age25to34 and toronto. c2 bids more, but it targets male, which the request does not have. c1 needs female and age25to34, and the request has both, so the answer is c1. The extra tag toronto does not matter. c3 targets no tags, so it matches every banner request. The last request has only age25to34: c1 also needs female and c2 needs male, so nothing matches.

Example 2

operations = ["INSERT a 100 native","QUERY native","INSERT b 100 native","INSERT c 150 native student","QUERY native","QUERY native student"]return = ["a","a","c"]

The first query sees only a. At the second query, b bids the same as a, and a was inserted first, so a stays the answer. c bids more but needs the tag student. The last request has that tag, so c wins it.

Example 3

operations = ["INSERT top 900 display sports male","INSERT mid 600 display sports","INSERT low 100 display","INSERT vid 950 video sports","QUERY display sports female","QUERY display male sports","QUERY audio sports"]return = ["mid","top","NONE"]

vid has the highest bid, but it is a video campaign, so it never answers a display request. For the first request, top needs male, so the next bid down, mid, wins. The second request has both of top's tags, in a different order, so top wins. No campaign has the format audio.

Constraints

  • 1 <= operations.length <= 1000
  • Each operation is "INSERT id bid format tag..." or "QUERY format tag...", with its words separated by single spaces.
  • At least one operation is a QUERY.
  • Each id has 1 to 10 characters, each a lowercase letter or a digit, and no two inserts use the same id.
  • Each bid is a whole number from 1 to 10^9, written without leading zeros.
  • Each format has 1 to 10 lowercase letters.
  • Each tag has 1 to 10 characters, each a lowercase letter or a digit. An operation has at most 6 tags, and no tag appears twice in one operation.

More StackAdapt interview questions

  • Build a Tree from Preorder and Inorder TraversalsONSITE INTERVIEW · Seen Sep 2026
  • Maximum Bananas Delivered by a CamelONSITE INTERVIEW · Seen Sep 2026
  • Reservoir Sampling with Recorded DrawsONSITE INTERVIEW · Seen Sep 2026
  • Rate Limiter with a Sliding Window per ClientPHONE SCREEN · Seen Nov 2026
  • Subtract Two Large Number StringsPHONE SCREEN · Seen Nov 2026
  • Running Medians and PercentilesPHONE SCREEN · Seen Aug 2026
  • Nested Recipe Inventory ManagerPHONE SCREEN · Seen Jul 2026

Similar questions at other companies

  • File System Shell CommandsHarvey · ONSITE INTERVIEWHarvey interview questions
  • In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
  • Implement uniq: Unique LinesVanta · ONSITE INTERVIEW
  • Most-Frequent Next-Word PredictorGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Text Embedding and Vector SearchNike, Inc. · PHONE SCREEN · ONSITE INTERVIEWNike, Inc. interview questions
  • Substitution Cipher Dictionary MatcherRemitly · ONSITE INTERVIEWRemitly interview questions
  • Most-Frequent Next-Word PredictorBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Account Scheduler - Availability and AcquireStripe · ONSITE INTERVIEWStripe interview questions
  • In-Memory Directory and File OperationsSquarepoint Capital · ONSITE INTERVIEWSquarepoint Capital interview questions
  • In-Memory Spreadsheet ValuesRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
All StackAdapt interview questionsSee StackAdapt hiring insights
Saved
class Solution {
    public String[] matchCampaigns(String[] operations) {
        // Write your code here.
    }
}
Checking account…