The problem
The codebase is an e-commerce catalog with order history and a search/recommendation layer. search/indexes.py and search/search_service.py are editable; the rest of the tree is reference code.
Make text_search and cooccurrence_recommend hit the perf targets below, with results unchanged.
The starter implementations are correct but re-scan the catalog or the order list on every call. They won't fit the budgets at scale.
Contracts (don't change the public signatures):
SearchService.search(query, category, min_price, max_price, top_k) -> List[Product]— AND across query tokens, then category, then[min_price, max_price], capped totop_k. Results are ordered by price ascending.SearchService.recommend(product_id, top_k) -> List[Tuple[str, int]]—(other_product_id, count), where count is the number of orders containing both products, sorted by count descending, then id ascending, capped totop_k.
Perf targets. rebuild(products, orders) is not timed (it may be called again with a new dataset); the queries after it are:
- 1,000
cooccurrence_recommendcalls on 20k products and 40k orders: under 1 s in total. - 520 distinct
text_searchqueries of one or two tokens on a 150k-product catalog: under 0.1 s in total. - 5 top-20
cooccurrence_recommendcalls for a best-seller co-ordered with 50k other products: under 0.75 s in total.
A per-query full scan won't fit the first two.
Done when Submit goes green.
Input: p1 Laptop Pro (computers, 999.99), p2 Wireless Mouse (accessories, 25.00), p3 Laptop Sleeve (accessories, 19.99) search(query="laptop", min_price=0.0, max_price=2000.0, top_k=10)
Output: [p3, p1]
Token 'laptop' matches p1 and p3; both are in the price range; ordered by price ascending.
Input: Same products; orders o1 = [p1, p2], o2 = [p1, p3]
recommend("p1", top_k=5)Output: [("p2", 1), ("p3", 1)]p1 shares one order with p2 and one with p3. Counts are equal, so order by product id ascending: p2 then p3.
Constraints
- Python 3.9+ standard library only
- Time limit: 10 seconds per test
- Only search/indexes.py and search/search_service.py are editable
- Products per dataset: up to ~150,000
- Orders per dataset: up to ~50,000
- Product price range: 0.0–1e6
The files you get
- Yours to edit: search/indexes.py, search/search_service.py.
- Read-only: api/app.py, models/customer.py, models/order.py, models/product.py, services/catalog.py, services/customers.py, services/inventory.py, services/notifications.py, services/orders.py.
- Tests you can read and run: tests/test_search.py, public_tests/test_stage_2.py. Hidden tests run on Submit.
The round: an agent in the editor
The assistant here works like the one in the interview IDE. It reads your files, runs code and proposes changes, and you accept or reject each one. It doesn't volunteer ideas, so what gets built is what you asked for. Along the way the interviewer asks about your decisions, and at the end the report says what you checked and what you accepted unread.
Frequently asked, briefly answered
Is Search And Recommendation Indexes free?
It is a Pro problem. Free plan includes one complete problem, plus the first stage of several more, so you can see how a round works before you pay.
Which company asks something like this?
No single company. It is practice for the format itself: an existing codebase, an assistant in the editor and a bar that rises stage by stage.
Do I bring my own AI tool?
No. The assistant is in the editor, same as in the interview IDEs at Meta, Stripe and Amazon. What you choose at Begin is the format: an agent that proposes changes you accept or reject, an answer-only assistant that can't write code, or no assistant at all.
What does the interviewer ask?
One question at the end about the whole session, your own code and your decisions. Your answer goes into the report.
Start the problem
Sign in and the problem opens where you left it. New here? An account takes a minute to create, and the Pro plan starts at the first stage of this problem.
More like it: every practice problem, the AI coding interview guide.