Median Home Price by City
Problem statement
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.