FastPrepMedian Home Price by City
Problems/Median Home Price by City

Median Home Price by City

Airbnb logoAirbnb● MediumFULLTIMEOA
QuestionFunctionExamplesConstraints

Problem statement

Source note: The OA report directly describes a city-to-list/dictionary input and asks for each city's home-price median. The portable flat entry encoding and exact formatting are assumptions; match is about 95%.

Each entry is city price, where city has no spaces and price is a nonnegative integer. Return one city=median string per city, sorted by city.

For an even count, use the mean of the two middle values. Medians are formatted as an integer or with a .5 suffix.

Function

cityPriceMedians(entries: String[]) → String[]

Examples

Example 1

entries = ["sf 10","ny 4","sf 20","ny 8","sf 30"]return = ["ny=6","sf=20"]

Each city's prices are ordered independently.

Example 2

entries = ["a 1","a 2"]return = ["a=1.5"]

The average of the two middle integers may be a half.

Example 3

entries = ["z 0"]return = ["z=0"]

A singleton's value is its median.

Constraints

  • 1 <= entries.length <= 2 * 10^5.
  • City names contain lowercase letters and prices fit signed 32-bit integers.

More Airbnb problems

  • Credit Accounts with Scheduled TransfersOA · Seen Oct 2026
  • Decode and Store StringsPHONE SCREEN · Seen Oct 2026
  • Parcel Attribute Store with TTLOA · Seen Oct 2026
All Airbnb interview questionsSee Airbnb hiring insights
Saved
class Solution {
    public String[] cityPriceMedians(String[] entries) {
        // Write your solution here.
    }
}
Checking account…