FastPrepAverage Purchase Price
Problems/Average Purchase Price

Average Purchase Price

WhatNot logoWhatNot● EasyFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: An engineer who was changing jobs met this at Whatnot between July and September 2022, in the third round of a process that had a phone part and an onsite part; it took place on the day of the second round. The prompt was framed as a product manager's request: find the mean price of purchases. No input format came with it, so the candidate defined the purchase data and wrote a function for it. After that, the interviewer asked again and again for a more optimized version without saying what to improve. The candidate did not get through this onsite.

Since the round fixed no input, this version picks one: purchases and requests arrive mixed, and each request asks for one item's mean in whole cents, rounded down. We read the repeated push to optimize as keeping a running total and count per item, so each request is answered at once.

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

A product manager wants to see the average price that buyers pay for each item. Purchases and requests for the average come in one at a time, as the array events in arrival order. Each event is one of these:

  • "BUY item price": someone bought item for price cents.
  • "AVG item": a request for the average price of all purchases of item that came before this event.

The average is the total of those prices divided by how many there are, rounded down to a whole number of cents. If item has no purchases yet, the answer is -1.

Return the answers to the AVG events, in the order the events appear.

Function

averagePrices(events: String[]) → int[]

Examples

Example 1

events = ["BUY mug 1200","BUY mug 1500","AVG mug","BUY hat 999","AVG hat","AVG mug"]return = [1350,999,1350]

The two mug purchases cost 1200 and 1500, so the average is 2700 / 2 = 1350. The hat has one purchase at 999. The purchase of a hat does not change the average for mug, which is still 1350.

Example 2

events = ["AVG card","BUY card 5","BUY card 6","AVG card"]return = [-1,5]

The first query comes before any card purchase, so its answer is -1. Later the average is 11 / 2 = 5.5, which rounds down to 5.

Example 3

events = ["BUY a1 1","BUY a1 1","BUY a1 2","AVG a1","AVG b2"]return = [1,-1]

Three purchases add up to 4, and 4 / 3 rounds down to 1. Nobody has bought b2, so that query returns -1.

Example 4

events = ["BUY tv 1000000","BUY tv 1000000","BUY tv 999999","AVG tv","BUY tv 1","AVG tv"]return = [999999,750000]

The first three purchases add up to 2999999, and 2999999 / 3 rounds down to 999999. After a fourth purchase at 1, the total is 3000000 over 4 purchases, so the average is 750000.

Constraints

  • 1 <= events.length <= 2 * 104
  • Each event is "BUY item price" or "AVG item", with single spaces. item has 1 to 10 lowercase letters or digits, and price is an integer written without leading zeros.
  • 1 <= price <= 106
  • There are between 1 and 5000 AVG events.

More WhatNot Onsite Interview questions

  • User Journey PathsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Search a 2D MatrixPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Detect Blocked Chat PhrasesPHONE SCREEN · ONSITE INTERVIEW · Seen Jun 2026
  • Minimum Remove to Make Valid ParenthesesONSITE INTERVIEW · Seen Dec 2024
  • Number of IslandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2024
  • Merge Two Sorted ListsONSITE INTERVIEW · Seen Jul 2024
  • Number of Submatrices That Sum to TargetONSITE INTERVIEW · Seen Jul 2024
  • Parse and Store Log RecordsONSITE INTERVIEW · Seen Oct 2023
  • Room Occupancy at Query TimesONSITE INTERVIEW · Seen Oct 2023
  • K Smallest Values in a StreamPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2022

Similar questions at other companies

  • Count Adjacent Symbol Pairs for BPEAmazon · ONSITE INTERVIEW
  • Count a User's Actions in an Event LogMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Map and Accumulate Learning QueriesPalantir · ONSITE INTERVIEWPalantir interview questions
  • Filter Pins by Excluded IDsPinterest · ONSITE INTERVIEWPinterest interview questions
  • First Non-Repeating CharacterGoldman Sachs · PHONE SCREEN · ONSITE INTERVIEWGoldman Sachs interview questions
  • Longest Dictionary Word from Nine LettersGoogle · ONSITE INTERVIEWGoogle interview questions
  • Minimum Replacements to Make Two Strings AnagramsBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Logger Rate LimiterAmazon Web Services · ONSITE INTERVIEWAmazon Web Services interview questions
  • Isomorphic StringsRemitly · ONSITE INTERVIEWRemitly interview questions
  • Check AnagramsDeloitte · ONSITE INTERVIEWDeloitte interview questions

WhatNot interview experiences

  • Whatnot SWE New Grad Second Technical Interview: 8 Experiences
  • Whatnot interviews · October 2026
  • Whatnot Experienced SWE Phone Screen Questions: 2 Experiences
  • Whatnot SWE Interview Questions: 6 Experiences
All WhatNot interview questionsSee WhatNot hiring insights
Saved
class Solution {
    public int[] averagePrices(String[] events) {
        // write your code here
    }
}
Checking account…