FastPrepHouse Valuation

House Valuation

IMC Trading logoIMC Trading● HardNEW GRADOA
Learn

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.

The worked source table supports population standard deviation and original-peer classification. The halfway rule and constant mean for a single surviving distinct area are explicit practice assumptions resolving omissions in the source.

Function

findValuation(reqArea: int, area: int[], price: int[]) → int

Examples

Example 1

reqArea = 1200area = [1500,500,1000,2000,2500]price = [30000,10000,20000,40000,50000]return = 24000

This is the complete photographed sample. Every 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 = 19375

A corroborating original capture explicitly gives this six-house result. Both area-1300 houses are outliers against their sole, differently priced peer. The area-1200 prices stay, with mean 13000. Interpolating to area 2000 gives 13000 + 300 * 17000 / 800 = 19375.

Example 3

reqArea = 800area = [1000,1000]price = [10000,20000]return = 1000

Each 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 = 1001

No 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 = 30625

This is the photographed second official sample. For 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 <= 100000
  • 500 <= reqArea, area[i] <= 100000
  • 1000 <= price[i] <= 1000000
  • Input arrays may be unsorted and may contain repeated areas and prices.

More IMC Trading problems

See IMC Trading hiring insights
public int findValuation(int reqArea, int[] area, int[] price) {
    // Write your solution here.
}
reqArea1200
area[1500,500,1000,2000,2500]
price[30000,10000,20000,40000,50000]
expected24000
Checking account…