FIFO FizzBuzz Market Matching
Updated
Problem statement
In the FizzBuzz market, Fizz units are traded for Buzz units. You receive offers in priority order. The offer at index i has type types[i], participant names[i], and quantity quantities[i].
Process offers from left to right using these rules:
- A Fizz offer can match only a Buzz offer.
- Waiting offers of each type are matched first-in, first-out.
- Partial matches are allowed. Any remaining quantity stays at the front of its queue, or a remaining incoming quantity joins the back of its own queue.
- Aggregate every match between the same ordered pair of participant names, even when it occurs through several offers.
Return one announcement for each participant pair that traded, ordered by the pair's first match. Format each announcement as FizzBuzz! <amount> <FizzName>:<BuzzName>.
Function
matchFizzBuzzOffers(types: String[], names: String[], quantities: int[]) → String[]Examples
Example 1
types = ["Fizz","Buzz","Buzz","Fizz","Buzz"]names = ["Alice","Bob","Catherine","Alice","Bob"]quantities = [5,3,4,4,2]return = ["FizzBuzz! 5 Alice:Bob","FizzBuzz! 4 Alice:Catherine"]Alice first trades three units with Bob and two with Catherine. Her later Fizz offer trades two more with Catherine and two more with Bob, so both repeated pairs are aggregated.
Example 2
types = ["Buzz","Fizz","Fizz"]names = ["Bina","Faye","Finn"]quantities = [4,2,5]return = ["FizzBuzz! 2 Faye:Bina","FizzBuzz! 2 Finn:Bina"]The waiting Buzz offer is partially filled by Faye, then its remaining quantity is filled by Finn.
Example 3
types = ["Fizz","Fizz"]names = ["A","B"]quantities = [2,3]return = []No Buzz offer arrives, so no trade is announced.
Constraints
0 <= types.length == names.length == quantities.length <= 200000.- Every value in
typesisFizzorBuzz. - Every participant name is non-empty.
1 <= quantities[i] <= 10^9.- The total quantity aggregated for any participant pair fits in a signed 64-bit integer.
More Google Onsite Interview questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Stateful Paginated Fetch NLyft · PHONE SCREENLyft interview questions
- Machine Message RouterOpenAI · PHONE SCREENOpenAI interview questions
- Capital Gains Tax from TradesArcesium · OAArcesium interview questions
- Incident MonitorStripe · OAStripe interview questions
- Sustained Overspeed AlertsFleetx · ONSITE INTERVIEW
- Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
- Random Dasher Set OperationsDoorDash · ONSITE INTERVIEWDoorDash interview questions
- Propagating Fraud DetectorAffirm · PHONE SCREEN · ONSITE INTERVIEWAffirm interview questions
- Constant-Time Weighted Pick with an Alias TableEtched · PHONE SCREEN
- Order and Batch Open-Close LifecycleHudson River Trading · PHONE SCREENHudson River Trading interview questions