FastPrepCD Rental System
Problems/CD Rental System

CD Rental System

Okta logoOkta● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

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. Sort them by price from low to high. If two shops have the same price, the smaller shop id comes first. Return the shop ids as one string, separated by spaces. If no shop has an available copy, return EMPTY.
  • RENT|shop|cd: rent CD cd from shop. This works only if that shop has an available copy of that CD right now. Return OK if it works, or INVALID if it does not.
  • UNRENT|shop|cd: return CD cd to shop. This works only if that CD was rented from that shop earlier and has not been returned yet. Return OK if it works, or INVALID if it does not.

Overview

In class form, this is a CD rental system whose data starts in the shape [shop, cd, price]. It has a search(cd) method that sorts by price, then by shop id. It also has rent(shop, cd) and unrent(shop, cd) methods that check availability first.

Your function

Here you write one function instead of a class. It runs the commands in order and returns an answer for each one. Besides shop id lists, the answers are OK, INVALID, and EMPTY.

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 interview questions

  • Simple Bank OperationsONSITE INTERVIEW · Seen Oct 2026
  • Randomized Collection with Duplicate ValuesONSITE INTERVIEW · Seen Sep 2026
  • Top-Down Employee Reporting ForestONSITE INTERVIEW · Seen Sep 2026
  • Fair Multi-Tenant CacheONSITE INTERVIEW · Seen Aug 2026
  • House Robber IIIPHONE SCREEN · Seen Nov 2026
  • Role-Based Network Access ControlPHONE SCREEN · Seen Aug 2026
  • Lexicographically Smallest Dependency OrderPHONE SCREEN · Seen Aug 2026

Similar questions at other companies

  • In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
  • Camel CardsRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
  • Banking System with Top ActivityCapital One · ONSITE INTERVIEWCapital One interview questions
  • Calendar Event System with Pagination and IntersectionLead Bank · ONSITE INTERVIEWLead Bank interview questions
  • Order Manager with Partial Cancellations and Indexed QueriesStripe · ONSITE INTERVIEWStripe interview questions
  • Set Command SimulationPure Storage · ONSITE INTERVIEWPure Storage interview questions
  • Worker Management with Promotions and Double-Paid TimeInstacart · ONSITE INTERVIEWInstacart interview questions
  • Recipe Rating ServiceNubank · PHONE SCREEN
  • Banking System with Pending Transfer AcceptanceCircle · PHONE SCREENCircle interview questions
  • Streaming Top-K Frequent ElementsNVIDIA · PHONE SCREENNVIDIA interview questions
All Okta interview questionsSee Okta hiring insights
Saved
class Solution {
    public String[] processCdRentalCommands(String[][] entries, String[] commands) {
      // write your code here
    }

}
Checking account…