House Valuation
Updated
Problem statement
Estimate a house price from historical sales. Sale i has area area[i] and price price[i]; the candidate house has area reqArea. Return its estimated price as an integer.
1. Remove outliers
For each sale, form a comparison list containing all other original sales of exactly the same area. An empty comparison list never makes the sale an outlier. Otherwise let mu be the comparison mean and use population standard deviation:
sigma = sqrt(sum((value - mu)^2) / comparisonCount).
The sale is an outlier exactly when abs(price[i] - mu) > 3 * sigma. Equality is retained. Classify every sale against the unchanged original data, then remove all classified outliers simultaneously.
2. Estimate from retained sales
- If none remain, use
1000. - If exactly one remains, use its price.
- If retained sales have area
reqArea, use their mean price. - If only one distinct area remains, use that area's mean price for any request.
- Otherwise, form the mean retained price at every distinct area. For a request between two areas, use the nearest lower and higher areas. Below the minimum area, use the two smallest areas; above the maximum, use the two largest areas.
For the chosen points (x1,y1) and (x2,y2), where x1 < x2, evaluate y1 + (reqArea - x1) * (y2 - y1) / (x2 - x1). Keep means and interpolation exact until the final result.
3. Clamp and round
Clamp the estimate to [1000,1000000], then round to the nearest integer. An exact halfway value rounds upward: for example, 1000.5 becomes 1001.
Function
findValuation(reqArea: int, area: int[], price: int[]) → intExamples
Example 1
reqArea = 1200area = [1500,500,1000,2000,2500]price = [30000,10000,20000,40000,50000]return = 24000Every area is unique, so no house is removed. Interpolate between (1000,20000) and (1500,30000): 20000 + 200 * 10000 / 500 = 24000.
Example 2
reqArea = 1500area = [1200,1300,1200,1300,1200,2000]price = [12000,24000,14000,22000,13000,30000]return = 19375Both area-1300 houses are outliers against their sole, differently priced peer. The area-1200 prices stay, with mean 13000. Interpolating between areas 1200 and 2000 at area 1500 gives 13000 + 300 * 17000 / 800 = 19375.
Example 3
reqArea = 800area = [1000,1000]price = [10000,20000]return = 1000Each sale has a sole same-area peer, so the comparison standard deviation is zero. Both differing prices are classified from the original data and removed simultaneously. With no houses left, return 1000.
Example 4
reqArea = 1000area = [1000,1000,1000,1000]price = [1000,1000,1001,1001]return = 1001No price is an outlier. The exact-area mean is 1000.5; the explicit half-up convention returns 1001.
Example 5
reqArea = 2500area = [1200,1200,1200,2000]price = [15000,11000,17000,25000]return = 30625For the three area-1200 prices, classify each sale against the other two original prices. Only 11000 is an outlier: its comparison mean is 16000, its population standard deviation is 1000, and 5000 > 3 * 1000. The 15000 and 17000 sales remain; their mean is 16000. The sole area-2000 sale remains at 25000. Extrapolate above the largest area using these two area means: 25000 + (2500 - 2000) * (25000 - 16000) / (2000 - 1200) = 30625. Clamping and rounding leave the result unchanged.
Constraints
1 <= area.length = price.length <= 100000500 <= reqArea, area[i] <= 1000001000 <= price[i] <= 1000000- Input arrays may be unsorted and may contain repeated areas and prices.
More IMC Trading Online Assessment questions
- Earliest Meeting Start on a 24-Hour ClockOA · Seen Nov 2026
- Grid Paths with Override PassesOA · Seen Oct 2026
- Weighted LFU CacheOA · Seen Sep 2026
- Rock JumpingOA · Seen Aug 2026
- Stack Batch RemovalOA · Seen Aug 2026
- Chain of CommandOA · Seen Aug 2026
- Choose ContainersOA · Seen Aug 2026
- Sub-matrix SumsOA · Seen Jul 2026
- Sub-matrix SumsOA · Seen Jul 2026
- Can Every Package Fit in a BoxOA · Seen Jul 2026
Similar questions at other companies
- Employee Count Median, Mean and ModeClay · PHONE SCREEN
- Text Embedding and Vector SearchNike, Inc. · PHONE SCREEN · ONSITE INTERVIEWNike, Inc. interview questions
- Find Accounts with Negative Converted BalancesStripe · PHONE SCREENStripe interview questions
- Numbers With Exactly Two Square-Sum RepresentationsGoogle · PHONE SCREENGoogle interview questions
- Median of Parsed Integer StringsRippling · PHONE SCREENRippling interview questions
- Implement k-Nearest NeighborsApple · PHONE SCREENApple interview questions
- Net Position Calculation from API SnapshotsHeadlands Technologies · ONSITE INTERVIEWHeadlands Technologies interview questions
- In-Memory File SystemAirbnb · OAAirbnb interview questions
- Power Cell BankOptiver · OAOptiver interview questions
- Delete and Freeze GameRubrik · OARubrik interview questions