Design Movie Rental System - Problem
๐ฌ Movie Rental Empire Challenge
You're tasked with building the backend system for a movie rental empire with n shops across the city! Your system needs to handle the core operations that keep customers happy: searching for movies, renting them out, returning them, and generating business reports.
Each movie copy is represented as [shop_id, movie_id, price] where:
- shop_id: Which shop has this copy
- movie_id: The movie identifier
- price: Rental price for this specific copy
Important: Each shop can only have one copy of any given movie.
Your Mission:
search(movie)- Find the 5 cheapest shops with available copies (unrented)rent(shop, movie)- Rent out a specific movie from a specific shopdrop(shop, movie)- Return a rented movie to its shopreport()- Get the 5 cheapest currently rented movies for business analytics
All results must be sorted by price first, then by shop ID, then by movie ID for ties! ๐ฏ
Input & Output
example_1.py โ Basic Operations
$
Input:
MovieRentingSystem(3, [[0,1,5],[0,2,6],[0,3,7],[1,1,4],[1,2,7],[2,1,5]])
search(1) -> rent(0,1) -> rent(1,2) -> report() -> drop(1,2) -> search(2)
โบ
Output:
[1,0,2] -> [] -> [] -> [[0,1],[1,2]] -> [] -> [0,2]
๐ก Note:
Initially movie 1 available at shops 1($4), 0($5), 2($5) - return [1,0,2]. After renting, report shows cheapest rented movies. After dropping, movie 2 becomes available at shop 0.
example_2.py โ Tie Breaking
$
Input:
MovieRentingSystem(2, [[0,1,5],[1,1,5],[0,2,3],[1,2,8]])
search(1) -> rent(0,1) -> search(1)
โบ
Output:
[0,1] -> [] -> [1]
๐ก Note:
Both shops have movie 1 at $5, but shop 0 comes first (smaller shop ID). After renting from shop 0, only shop 1 has it available.
example_3.py โ Empty Results
$
Input:
MovieRentingSystem(1, [[0,1,3]])
search(2) -> rent(0,1) -> search(1) -> report()
โบ
Output:
[] -> [] -> [] -> [[0,1]]
๐ก Note:
Movie 2 doesn't exist, so search returns empty. After renting movie 1, it's no longer available for search, but shows up in report.
Constraints
- 1 โค n โค 3 ร 105
- 1 โค entries.length โค 105
- 0 โค shopi < n
- 1 โค moviei, pricei โค 105
- Each shop carries at most one copy of movie moviei
- All calls to rent and drop are valid
- At most 105 calls in total to search, rent, drop, and report
๐ก
Explanation
AI Ready
๐ก Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code