Problem
Build an in-memory index over home Listing records (id, city, price, beds). getById(id) returns the matching Listing in O(1), or null if absent. search(city, maxPrice) returns the ids of listings in that city priced at or below maxPrice, cheapest first, ties broken by id ascending. Re-adding the same id must update the existing record, not duplicate it.
The AI is deliberately fallible — it gives hints, not solutions, and sometimes proposes wrong code. It cannot touch your editor. Paste what you choose, then Run. Anything AI-derived stays UNVERIFIED until your tests go green.
Self-check
- ☐getById is a hash lookup (O(1)), not a scan of all listings
- ☐search filters by exact city and an inclusive price ceiling
- ☐results are ordered by price ascending, with id ascending as the tie-break
- ☐re-adding an existing id updates the record in place (no duplicates)
- ☐you named the time/space cost of search and what you would add for scale (a sorted or per-city index)
Hints / what this doesn't test
This is an Opendoor-flavored applied problem: model records and serve two access
patterns — a point lookup and a filtered, ranked query. Restate it first — "So
getById has to be O(1), and search is a city + price-ceiling filter sorted by
price then id, and adding a known id is an upsert?"
What this problem does not test (say so out loud): pagination, multi-field
filters (beds, geo radius), full-text matching, and a precomputed sorted index per
city are out of scope here — but a senior names that the linear scan in search is
the obvious scaling cost and that a per-city price-sorted structure is the next step.
Tests
- ○by_id
- ○by_id_missing
- ○search_filter
- ○search_rank
- + 2 hidden tests — revealed once the visible ones pass
Pair partner (병신 모드 · 버그 잡기)
gpt-4o-miniAsk for a skeleton or a test plan — not the answer. Then implement the core yourself and come back for edge cases. Remember: the partner is fallible. Verify everything by running it.
The partner sees your editor but cannot change it. Copy any suggestion in by hand, then Run to verify.
AI랑 먼저 페어하고 눌러