FastPrepCD Rental System
Problems/CD Rental System

CD Rental System

Okta logoOkta● MediumFULLTIMEONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: This came from a real onsite interview report. The original report shared the CD rental APIs and sorting rule, and FastPrep filled in the command-runner format, return strings, examples, and constraints so you can practice it here. Estimated match rate: 85% for the core task, 70% for interface and examples, and 35% for exact original wording. If you find a fuller version, feel free to let us know and we will update it.

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.

More Okta problems

  • Simple Bank OperationsONSITE INTERVIEW · Seen Oct 2026
  • Simple Bank OperationsONSITE INTERVIEW · Seen Oct 2026
  • Randomized Collection with Duplicate ValuesONSITE INTERVIEW · Seen Sep 2026
All Okta interview questionsSee Okta hiring insights
Saved
public String[] processCdRentalCommands(String[][] entries, String[] commands) {
  // write your code here
}
Checking account…