CD Rental System
Reported by candidates from Okta's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The Okta OA reported in July 2026 is a design question dressed up as a command parser, and the data structure you pick decides everything. You get [shop, cd, price] entries, then up to 100000 SEARCH, RENT and UNRENT commands. SEARCH has to return shops sorted by price, then shop id, among copies that are currently available. If you rescan and re-sort per query, you'll time out. If you blank on the structure, StealthCoder is the invisible safety net running during the live OA. Know the shape before you open the invite.
The problem
Design a small in-memory CD rental system. You are given an initial list of CD inventory entries. Each entry is [shop, cd, price], meaning shop shop owns one copy of CD cd with rental price price. The system then receives commands. Return one output string for each command. Commands SEARCH|cd: return all shops that currently have CD cd available, sorted by price ascending, then shop id ascending. Return the shop ids as a single space-separated string. If no shop has an available copy, return EMPTY. RENT|shop|cd: rent CD cd from shop. This succeeds only if that shop currently has an available copy of that CD. Return OK on success or INVALID otherwise. UNRENT|shop|cd: return CD cd to shop. This succeeds only if that CD was previously rented from that shop and has not already been returned. Return OK on success or INVALID otherwise. What the interview report shared The interview report described an onsite Java and DSA/LLD round where the candidate had to design and implement a CD rental system. It shared the initial data shape [shop, cd, price], the search(cd) API sorted by price then shop id, and the rent(shop, cd) and unrent(shop, cd) APIs with availability checks. The report did not specify command serialization, exact return strings, or sample inputs. How FastPrep adapted it FastPrep turned the class-style interview task into a single command-processing function. The OK, INVALID, and EMPTY outputs are practice scaffolding based on the reported APIs, not exact original wording. Function processCdRentalCommands(entries: String[][], commands: String[]) → String[] Examples Example 1 entries = [["1","10","5"],["2","10","4"],["1","20","6"]] commands = ["SEARCH|10","RENT|2|10","SEARCH|10","RENT|2|10","UNRENT|2|10","SEARCH|10"] return = ["2 1","OK","1","INVALID","OK","2 1"] Before any rental, CD 10 is available at shop 2 for price 4 and shop 1 for price 5, so shop 2 comes first. After renting from shop 2, only shop 1 remains available until the CD is returned. Example 2 entries = [["3","7","8"],["4","7","8"],["5","8","2"]] commands = ["SEARCH|7","RENT|4|7","SEARCH|7","UNRENT|3|7","UNRENT|4|7","SEARCH|7","SEARCH|9"] return = ["3 4","OK","3","INVALID","OK","3 4","EMPTY"] Shops 3 and 4 have the same price for CD 7, so the smaller shop id comes first. Returning from shop 3 is invalid because that copy was never rented. Constraints 1 <= entries.length <= 100000 1 <= commands.length <= 100000 Each [shop, cd] pair appears at most once in entries. 1 <= shop, cd, price <= 10^9 Commands are always one of SEARCH, RENT, or UNRENT with the field counts shown above.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is a per-CD ordered set of available copies, keyed by (price, shop). Use a map from cd to a sorted set (TreeSet in Java, or a heap with lazy deletion). Keep a second map from (shop, cd) to price, plus a rented flag. RENT checks that the pair exists and is available, removes it from the sorted set, and marks it rented. UNRENT checks the pair is currently rented, then reinserts it. SEARCH just walks the set for that cd and joins the shop ids, or returns EMPTY. The common pitfall is sorting on every SEARCH, or treating UNRENT as valid when the copy was never rented, like Example 2 with shop 3. Another is parsing the pipe-delimited commands wrong and mixing up the argument order. Values reach 10^9, so use long keys and don't pack shop and cd into a naive int. If you freeze on the ordered-set choice mid-assessment, StealthCoder can hand you the working structure while you keep typing.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill CD Rental System cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as design movie rental system. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Okta's OA.
Okta reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
CD Rental System FAQ
What's the core trick in the Okta CD rental system problem?+
Keep available copies per CD in a sorted structure keyed by (price, shop id). That makes SEARCH an ordered read instead of a sort, and RENT and UNRENT become log-time remove and insert operations. A second map tracks each shop and CD pair's price and rented state.
How hard is this one really?+
Medium on difficulty, but easy to botch on details. The algorithm is simple once you pick the ordered set. Most failures come from INVALID edge cases, tie-breaking by shop id, and slow per-query sorting at 100000 commands.
Can I use a heap instead of a TreeSet?+
Yes, with lazy deletion. Push (price, shop) per CD, and when you search, skip entries that are rented. But SEARCH has to return all available shops in order, so you'd end up popping and re-pushing. A balanced ordered set is cleaner for this problem.
Which edge cases should I test before submitting?+
Renting the same copy twice, unrenting a copy that was never rented, unrenting twice, searching a CD that doesn't exist, and equal prices across shops. Also check that a rented copy disappears from SEARCH and comes back after UNRENT in the right position.
How do I prepare for this in 48 hours?+
Write one in-memory design class that uses a map of sorted sets plus a state map. Practice parsing pipe-separated commands and returning strings per command. Aim to write it cleanly in one pass, since design OAs reward tidy structure over clever algorithms.