Leetcode Problem 1912. Design Movie Rental System

1912. Design Movie Rental System

Leetcode Solutions

HashMap and TreeSet Approach

  1. Initialize a HashMap priceMap to store the price for each (shop, movie) pair.
  2. Initialize a TreeSet available for each movie to store available copies sorted by price and shop.
  3. Initialize a TreeSet rented to store rented movies sorted by price, shop, and movie.
  4. For the search operation, retrieve the first 5 entries from the available TreeSet for the given movie.
  5. For the rent operation, remove the entry from the available TreeSet and add it to the rented TreeSet.
  6. For the drop operation, remove the entry from the rented TreeSet and add it back to the available TreeSet for the given movie.
  7. For the report operation, retrieve the first 5 entries from the rented TreeSet.
UML Thumbnail

Sorted List and Dictionary Approach

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...