mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
174 lines
32 KiB
JSON
174 lines
32 KiB
JSON
{
|
|
"data": {
|
|
"question": {
|
|
"questionId": "2023",
|
|
"questionFrontendId": "1912",
|
|
"boundTopicId": null,
|
|
"title": "Design Movie Rental System",
|
|
"titleSlug": "design-movie-rental-system",
|
|
"content": "<p>You have a movie renting company consisting of <code>n</code> shops. You want to implement a renting system that supports searching for, booking, and returning movies. The system should also support generating a report of the currently rented movies.</p>\r\n\r\n<p>Each movie is given as a 2D integer array <code>entries</code> where <code>entries[i] = [shop<sub>i</sub>, movie<sub>i</sub>, price<sub>i</sub>]</code> indicates that there is a copy of movie <code>movie<sub>i</sub></code> at shop <code>shop<sub>i</sub></code> with a rental price of <code>price<sub>i</sub></code>. Each shop carries <strong>at most one</strong> copy of a movie <code>movie<sub>i</sub></code>.</p>\r\n\r\n<p>The system should support the following functions:</p>\r\n\r\n<ul>\r\n\t<li><strong>Search</strong>: Finds the <strong>cheapest 5 shops</strong> that have an <strong>unrented copy</strong> of a given movie. The shops should be sorted by <strong>price</strong> in ascending order, and in case of a tie, the one with the <strong>smaller </strong><code>shop<sub>i</sub></code> should appear first. If there are less than 5 matching shops, then all of them should be returned. If no shop has an unrented copy, then an empty list should be returned.</li>\r\n\t<li><strong>Rent</strong>: Rents an <strong>unrented copy</strong> of a given movie from a given shop.</li>\r\n\t<li><strong>Drop</strong>: Drops off a <strong>previously rented copy</strong> of a given movie at a given shop.</li>\r\n\t<li><strong>Report</strong>: Returns the <strong>cheapest 5 rented movies</strong> (possibly of the same movie ID) as a 2D list <code>res</code> where <code>res[j] = [shop<sub>j</sub>, movie<sub>j</sub>]</code> describes that the <code>j<sup>th</sup></code> cheapest rented movie <code>movie<sub>j</sub></code> was rented from the shop <code>shop<sub>j</sub></code>. The movies in <code>res</code> should be sorted by <strong>price </strong>in ascending order, and in case of a tie, the one with the <strong>smaller </strong><code>shop<sub>j</sub></code> should appear first, and if there is still tie, the one with the <strong>smaller </strong><code>movie<sub>j</sub></code> should appear first. If there are fewer than 5 rented movies, then all of them should be returned. If no movies are currently being rented, then an empty list should be returned.</li>\r\n</ul>\r\n\r\n<p>Implement the <code>MovieRentingSystem</code> class:</p>\r\n\r\n<ul>\r\n\t<li><code>MovieRentingSystem(int n, int[][] entries)</code> Initializes the <code>MovieRentingSystem</code> object with <code>n</code> shops and the movies in <code>entries</code>.</li>\r\n\t<li><code>List<Integer> search(int movie)</code> Returns a list of shops that have an <strong>unrented copy</strong> of the given <code>movie</code> as described above.</li>\r\n\t<li><code>void rent(int shop, int movie)</code> Rents the given <code>movie</code> from the given <code>shop</code>.</li>\r\n\t<li><code>void drop(int shop, int movie)</code> Drops off a previously rented <code>movie</code> at the given <code>shop</code>.</li>\r\n\t<li><code>List<List<Integer>> report()</code> Returns a list of cheapest <strong>rented</strong> movies as described above.</li>\r\n</ul>\r\n\r\n<p><strong>Note:</strong> The test cases will be generated such that <code>rent</code> will only be called if the shop has an <strong>unrented</strong> copy of the movie, and <code>drop</code> will only be called if the shop had <strong>previously rented</strong> out the movie.</p>\r\n\r\n<p> </p>\r\n<p><strong>Example 1:</strong></p>\r\n\r\n<pre>\r\n<strong>Input</strong>\r\n["MovieRentingSystem", "search", "rent", "rent", "report", "drop", "search"]\r\n[[3, [[0, 1, 5], [0, 2, 6], [0, 3, 7], [1, 1, 4], [1, 2, 7], [2, 1, 5]]], [1], [0, 1], [1, 2], [], [1, 2], [2]]\r\n<strong>Output</strong>\r\n[null, [1, 0, 2], null, null, [[0, 1], [1, 2]], null, [0, 1]]\r\n\r\n<strong>Explanation</strong>\r\nMovieRentingSystem movieRentingSystem = new MovieRentingSystem(3, [[0, 1, 5], [0, 2, 6], [0, 3, 7], [1, 1, 4], [1, 2, 7], [2, 1, 5]]);\r\nmovieRentingSystem.search(1); // return [1, 0, 2], Movies of ID 1 are unrented at shops 1, 0, and 2. Shop 1 is cheapest; shop 0 and 2 are the same price, so order by shop number.\r\nmovieRentingSystem.rent(0, 1); // Rent movie 1 from shop 0. Unrented movies at shop 0 are now [2,3].\r\nmovieRentingSystem.rent(1, 2); // Rent movie 2 from shop 1. Unrented movies at shop 1 are now [1].\r\nmovieRentingSystem.report(); // return [[0, 1], [1, 2]]. Movie 1 from shop 0 is cheapest, followed by movie 2 from shop 1.\r\nmovieRentingSystem.drop(1, 2); // Drop off movie 2 at shop 1. Unrented movies at shop 1 are now [1,2].\r\nmovieRentingSystem.search(2); // return [0, 1]. Movies of ID 2 are unrented at shops 0 and 1. Shop 0 is cheapest, followed by shop 1.\r\n</pre>\r\n\r\n<p> </p>\r\n<p><strong>Constraints:</strong></p>\r\n\r\n<ul>\r\n\t<li><code>1 <= n <= 3 * 10<sup>5</sup></code></li>\r\n\t<li><code>1 <= entries.length <= 10<sup>5</sup></code></li>\r\n\t<li><code>0 <= shop<sub>i</sub> < n</code></li>\r\n\t<li><code>1 <= movie<sub>i</sub>, price<sub>i</sub> <= 10<sup>4</sup></code></li>\r\n\t<li>Each shop carries <strong>at most one</strong> copy of a movie <code>movie<sub>i</sub></code>.</li>\r\n\t<li>At most <code>10<sup>5</sup></code> calls <strong>in total</strong> will be made to <code>search</code>, <code>rent</code>, <code>drop</code> and <code>report</code>.</li>\r\n</ul>",
|
|
"translatedTitle": null,
|
|
"translatedContent": null,
|
|
"isPaidOnly": false,
|
|
"difficulty": "Hard",
|
|
"likes": 141,
|
|
"dislikes": 28,
|
|
"isLiked": null,
|
|
"similarQuestions": "[]",
|
|
"exampleTestcases": "[\"MovieRentingSystem\",\"search\",\"rent\",\"rent\",\"report\",\"drop\",\"search\"]\n[[3,[[0,1,5],[0,2,6],[0,3,7],[1,1,4],[1,2,7],[2,1,5]]],[1],[0,1],[1,2],[],[1,2],[2]]",
|
|
"categoryTitle": "Algorithms",
|
|
"contributors": [],
|
|
"topicTags": [
|
|
{
|
|
"name": "Array",
|
|
"slug": "array",
|
|
"translatedName": null,
|
|
"__typename": "TopicTagNode"
|
|
},
|
|
{
|
|
"name": "Hash Table",
|
|
"slug": "hash-table",
|
|
"translatedName": null,
|
|
"__typename": "TopicTagNode"
|
|
},
|
|
{
|
|
"name": "Design",
|
|
"slug": "design",
|
|
"translatedName": null,
|
|
"__typename": "TopicTagNode"
|
|
},
|
|
{
|
|
"name": "Heap (Priority Queue)",
|
|
"slug": "heap-priority-queue",
|
|
"translatedName": null,
|
|
"__typename": "TopicTagNode"
|
|
},
|
|
{
|
|
"name": "Ordered Set",
|
|
"slug": "ordered-set",
|
|
"translatedName": null,
|
|
"__typename": "TopicTagNode"
|
|
}
|
|
],
|
|
"companyTagStats": null,
|
|
"codeSnippets": [
|
|
{
|
|
"lang": "C++",
|
|
"langSlug": "cpp",
|
|
"code": "class MovieRentingSystem {\r\npublic:\r\n MovieRentingSystem(int n, vector<vector<int>>& entries) {\r\n \r\n }\r\n \r\n vector<int> search(int movie) {\r\n \r\n }\r\n \r\n void rent(int shop, int movie) {\r\n \r\n }\r\n \r\n void drop(int shop, int movie) {\r\n \r\n }\r\n \r\n vector<vector<int>> report() {\r\n \r\n }\r\n};\r\n\r\n/**\r\n * Your MovieRentingSystem object will be instantiated and called as such:\r\n * MovieRentingSystem* obj = new MovieRentingSystem(n, entries);\r\n * vector<int> param_1 = obj->search(movie);\r\n * obj->rent(shop,movie);\r\n * obj->drop(shop,movie);\r\n * vector<vector<int>> param_4 = obj->report();\r\n */",
|
|
"__typename": "CodeSnippetNode"
|
|
},
|
|
{
|
|
"lang": "Java",
|
|
"langSlug": "java",
|
|
"code": "class MovieRentingSystem {\r\n\r\n public MovieRentingSystem(int n, int[][] entries) {\r\n \r\n }\r\n \r\n public List<Integer> search(int movie) {\r\n \r\n }\r\n \r\n public void rent(int shop, int movie) {\r\n \r\n }\r\n \r\n public void drop(int shop, int movie) {\r\n \r\n }\r\n \r\n public List<List<Integer>> report() {\r\n \r\n }\r\n}\r\n\r\n/**\r\n * Your MovieRentingSystem object will be instantiated and called as such:\r\n * MovieRentingSystem obj = new MovieRentingSystem(n, entries);\r\n * List<Integer> param_1 = obj.search(movie);\r\n * obj.rent(shop,movie);\r\n * obj.drop(shop,movie);\r\n * List<List<Integer>> param_4 = obj.report();\r\n */",
|
|
"__typename": "CodeSnippetNode"
|
|
},
|
|
{
|
|
"lang": "Python",
|
|
"langSlug": "python",
|
|
"code": "class MovieRentingSystem(object):\r\n\r\n def __init__(self, n, entries):\r\n \"\"\"\r\n :type n: int\r\n :type entries: List[List[int]]\r\n \"\"\"\r\n \r\n\r\n def search(self, movie):\r\n \"\"\"\r\n :type movie: int\r\n :rtype: List[int]\r\n \"\"\"\r\n \r\n\r\n def rent(self, shop, movie):\r\n \"\"\"\r\n :type shop: int\r\n :type movie: int\r\n :rtype: None\r\n \"\"\"\r\n \r\n\r\n def drop(self, shop, movie):\r\n \"\"\"\r\n :type shop: int\r\n :type movie: int\r\n :rtype: None\r\n \"\"\"\r\n \r\n\r\n def report(self):\r\n \"\"\"\r\n :rtype: List[List[int]]\r\n \"\"\"\r\n \r\n\r\n\r\n# Your MovieRentingSystem object will be instantiated and called as such:\r\n# obj = MovieRentingSystem(n, entries)\r\n# param_1 = obj.search(movie)\r\n# obj.rent(shop,movie)\r\n# obj.drop(shop,movie)\r\n# param_4 = obj.report()",
|
|
"__typename": "CodeSnippetNode"
|
|
},
|
|
{
|
|
"lang": "Python3",
|
|
"langSlug": "python3",
|
|
"code": "class MovieRentingSystem:\r\n\r\n def __init__(self, n: int, entries: List[List[int]]):\r\n \r\n\r\n def search(self, movie: int) -> List[int]:\r\n \r\n\r\n def rent(self, shop: int, movie: int) -> None:\r\n \r\n\r\n def drop(self, shop: int, movie: int) -> None:\r\n \r\n\r\n def report(self) -> List[List[int]]:\r\n \r\n\r\n\r\n# Your MovieRentingSystem object will be instantiated and called as such:\r\n# obj = MovieRentingSystem(n, entries)\r\n# param_1 = obj.search(movie)\r\n# obj.rent(shop,movie)\r\n# obj.drop(shop,movie)\r\n# param_4 = obj.report()",
|
|
"__typename": "CodeSnippetNode"
|
|
},
|
|
{
|
|
"lang": "C",
|
|
"langSlug": "c",
|
|
"code": "typedef struct {\r\n \r\n} MovieRentingSystem;\r\n\r\n\r\nMovieRentingSystem* movieRentingSystemCreate(int n, int** entries, int entriesSize, int* entriesColSize) {\r\n \r\n}\r\n\r\nint* movieRentingSystemSearch(MovieRentingSystem* obj, int movie, int* retSize) {\r\n \r\n}\r\n\r\nvoid movieRentingSystemRent(MovieRentingSystem* obj, int shop, int movie) {\r\n \r\n}\r\n\r\nvoid movieRentingSystemDrop(MovieRentingSystem* obj, int shop, int movie) {\r\n \r\n}\r\n\r\nint** movieRentingSystemReport(MovieRentingSystem* obj, int* retSize, int** retColSize) {\r\n \r\n}\r\n\r\nvoid movieRentingSystemFree(MovieRentingSystem* obj) {\r\n \r\n}\r\n\r\n/**\r\n * Your MovieRentingSystem struct will be instantiated and called as such:\r\n * MovieRentingSystem* obj = movieRentingSystemCreate(n, entries, entriesSize, entriesColSize);\r\n * int* param_1 = movieRentingSystemSearch(obj, movie, retSize);\r\n \r\n * movieRentingSystemRent(obj, shop, movie);\r\n \r\n * movieRentingSystemDrop(obj, shop, movie);\r\n \r\n * int** param_4 = movieRentingSystemReport(obj, retSize, retColSize);\r\n \r\n * movieRentingSystemFree(obj);\r\n*/",
|
|
"__typename": "CodeSnippetNode"
|
|
},
|
|
{
|
|
"lang": "C#",
|
|
"langSlug": "csharp",
|
|
"code": "public class MovieRentingSystem {\r\n\r\n public MovieRentingSystem(int n, int[][] entries) {\r\n \r\n }\r\n \r\n public IList<int> Search(int movie) {\r\n \r\n }\r\n \r\n public void Rent(int shop, int movie) {\r\n \r\n }\r\n \r\n public void Drop(int shop, int movie) {\r\n \r\n }\r\n \r\n public IList<IList<int>> Report() {\r\n \r\n }\r\n}\r\n\r\n/**\r\n * Your MovieRentingSystem object will be instantiated and called as such:\r\n * MovieRentingSystem obj = new MovieRentingSystem(n, entries);\r\n * IList<int> param_1 = obj.Search(movie);\r\n * obj.Rent(shop,movie);\r\n * obj.Drop(shop,movie);\r\n * IList<IList<int>> param_4 = obj.Report();\r\n */",
|
|
"__typename": "CodeSnippetNode"
|
|
},
|
|
{
|
|
"lang": "JavaScript",
|
|
"langSlug": "javascript",
|
|
"code": "/**\r\n * @param {number} n\r\n * @param {number[][]} entries\r\n */\r\nvar MovieRentingSystem = function(n, entries) {\r\n \r\n};\r\n\r\n/** \r\n * @param {number} movie\r\n * @return {number[]}\r\n */\r\nMovieRentingSystem.prototype.search = function(movie) {\r\n \r\n};\r\n\r\n/** \r\n * @param {number} shop \r\n * @param {number} movie\r\n * @return {void}\r\n */\r\nMovieRentingSystem.prototype.rent = function(shop, movie) {\r\n \r\n};\r\n\r\n/** \r\n * @param {number} shop \r\n * @param {number} movie\r\n * @return {void}\r\n */\r\nMovieRentingSystem.prototype.drop = function(shop, movie) {\r\n \r\n};\r\n\r\n/**\r\n * @return {number[][]}\r\n */\r\nMovieRentingSystem.prototype.report = function() {\r\n \r\n};\r\n\r\n/** \r\n * Your MovieRentingSystem object will be instantiated and called as such:\r\n * var obj = new MovieRentingSystem(n, entries)\r\n * var param_1 = obj.search(movie)\r\n * obj.rent(shop,movie)\r\n * obj.drop(shop,movie)\r\n * var param_4 = obj.report()\r\n */",
|
|
"__typename": "CodeSnippetNode"
|
|
},
|
|
{
|
|
"lang": "Ruby",
|
|
"langSlug": "ruby",
|
|
"code": "class MovieRentingSystem\r\n\r\n=begin\r\n :type n: Integer\r\n :type entries: Integer[][]\r\n=end\r\n def initialize(n, entries)\r\n \r\n end\r\n\r\n\r\n=begin\r\n :type movie: Integer\r\n :rtype: Integer[]\r\n=end\r\n def search(movie)\r\n \r\n end\r\n\r\n\r\n=begin\r\n :type shop: Integer\r\n :type movie: Integer\r\n :rtype: Void\r\n=end\r\n def rent(shop, movie)\r\n \r\n end\r\n\r\n\r\n=begin\r\n :type shop: Integer\r\n :type movie: Integer\r\n :rtype: Void\r\n=end\r\n def drop(shop, movie)\r\n \r\n end\r\n\r\n\r\n=begin\r\n :rtype: Integer[][]\r\n=end\r\n def report()\r\n \r\n end\r\n\r\n\r\nend\r\n\r\n# Your MovieRentingSystem object will be instantiated and called as such:\r\n# obj = MovieRentingSystem.new(n, entries)\r\n# param_1 = obj.search(movie)\r\n# obj.rent(shop, movie)\r\n# obj.drop(shop, movie)\r\n# param_4 = obj.report()",
|
|
"__typename": "CodeSnippetNode"
|
|
},
|
|
{
|
|
"lang": "Swift",
|
|
"langSlug": "swift",
|
|
"code": "class MovieRentingSystem {\r\n\r\n init(_ n: Int, _ entries: [[Int]]) {\r\n \r\n }\r\n \r\n func search(_ movie: Int) -> [Int] {\r\n \r\n }\r\n \r\n func rent(_ shop: Int, _ movie: Int) {\r\n \r\n }\r\n \r\n func drop(_ shop: Int, _ movie: Int) {\r\n \r\n }\r\n \r\n func report() -> [[Int]] {\r\n \r\n }\r\n}\r\n\r\n/**\r\n * Your MovieRentingSystem object will be instantiated and called as such:\r\n * let obj = MovieRentingSystem(n, entries)\r\n * let ret_1: [Int] = obj.search(movie)\r\n * obj.rent(shop, movie)\r\n * obj.drop(shop, movie)\r\n * let ret_4: [[Int]] = obj.report()\r\n */",
|
|
"__typename": "CodeSnippetNode"
|
|
},
|
|
{
|
|
"lang": "Go",
|
|
"langSlug": "golang",
|
|
"code": "type MovieRentingSystem struct {\r\n \r\n}\r\n\r\n\r\nfunc Constructor(n int, entries [][]int) MovieRentingSystem {\r\n \r\n}\r\n\r\n\r\nfunc (this *MovieRentingSystem) Search(movie int) []int {\r\n \r\n}\r\n\r\n\r\nfunc (this *MovieRentingSystem) Rent(shop int, movie int) {\r\n \r\n}\r\n\r\n\r\nfunc (this *MovieRentingSystem) Drop(shop int, movie int) {\r\n \r\n}\r\n\r\n\r\nfunc (this *MovieRentingSystem) Report() [][]int {\r\n \r\n}\r\n\r\n\r\n/**\r\n * Your MovieRentingSystem object will be instantiated and called as such:\r\n * obj := Constructor(n, entries);\r\n * param_1 := obj.Search(movie);\r\n * obj.Rent(shop,movie);\r\n * obj.Drop(shop,movie);\r\n * param_4 := obj.Report();\r\n */",
|
|
"__typename": "CodeSnippetNode"
|
|
},
|
|
{
|
|
"lang": "Scala",
|
|
"langSlug": "scala",
|
|
"code": "class MovieRentingSystem(_n: Int, _entries: Array[Array[Int]]) {\r\n\r\n def search(movie: Int): List[Int] = {\r\n \r\n }\r\n\r\n def rent(shop: Int, movie: Int) {\r\n \r\n }\r\n\r\n def drop(shop: Int, movie: Int) {\r\n \r\n }\r\n\r\n def report(): List[List[Int]] = {\r\n \r\n }\r\n\r\n}\r\n\r\n/**\r\n * Your MovieRentingSystem object will be instantiated and called as such:\r\n * var obj = new MovieRentingSystem(n, entries)\r\n * var param_1 = obj.search(movie)\r\n * obj.rent(shop,movie)\r\n * obj.drop(shop,movie)\r\n * var param_4 = obj.report()\r\n */",
|
|
"__typename": "CodeSnippetNode"
|
|
},
|
|
{
|
|
"lang": "Kotlin",
|
|
"langSlug": "kotlin",
|
|
"code": "class MovieRentingSystem(n: Int, entries: Array<IntArray>) {\r\n\r\n fun search(movie: Int): List<Int> {\r\n \r\n }\r\n\r\n fun rent(shop: Int, movie: Int) {\r\n \r\n }\r\n\r\n fun drop(shop: Int, movie: Int) {\r\n \r\n }\r\n\r\n fun report(): List<List<Int>> {\r\n \r\n }\r\n\r\n}\r\n\r\n/**\r\n * Your MovieRentingSystem object will be instantiated and called as such:\r\n * var obj = MovieRentingSystem(n, entries)\r\n * var param_1 = obj.search(movie)\r\n * obj.rent(shop,movie)\r\n * obj.drop(shop,movie)\r\n * var param_4 = obj.report()\r\n */",
|
|
"__typename": "CodeSnippetNode"
|
|
},
|
|
{
|
|
"lang": "Rust",
|
|
"langSlug": "rust",
|
|
"code": "struct MovieRentingSystem {\r\n\r\n}\r\n\r\n\r\n/** \r\n * `&self` means the method takes an immutable reference.\r\n * If you need a mutable reference, change it to `&mut self` instead.\r\n */\r\nimpl MovieRentingSystem {\r\n\r\n fn new(n: i32, entries: Vec<Vec<i32>>) -> Self {\r\n \r\n }\r\n \r\n fn search(&self, movie: i32) -> Vec<i32> {\r\n \r\n }\r\n \r\n fn rent(&self, shop: i32, movie: i32) {\r\n \r\n }\r\n \r\n fn drop(&self, shop: i32, movie: i32) {\r\n \r\n }\r\n \r\n fn report(&self) -> Vec<Vec<i32>> {\r\n \r\n }\r\n}\r\n\r\n/**\r\n * Your MovieRentingSystem object will be instantiated and called as such:\r\n * let obj = MovieRentingSystem::new(n, entries);\r\n * let ret_1: Vec<i32> = obj.search(movie);\r\n * obj.rent(shop, movie);\r\n * obj.drop(shop, movie);\r\n * let ret_4: Vec<Vec<i32>> = obj.report();\r\n */",
|
|
"__typename": "CodeSnippetNode"
|
|
},
|
|
{
|
|
"lang": "PHP",
|
|
"langSlug": "php",
|
|
"code": "class MovieRentingSystem {\r\n /**\r\n * @param Integer $n\r\n * @param Integer[][] $entries\r\n */\r\n function __construct($n, $entries) {\r\n \r\n }\r\n \r\n /**\r\n * @param Integer $movie\r\n * @return Integer[]\r\n */\r\n function search($movie) {\r\n \r\n }\r\n \r\n /**\r\n * @param Integer $shop\r\n * @param Integer $movie\r\n * @return NULL\r\n */\r\n function rent($shop, $movie) {\r\n \r\n }\r\n \r\n /**\r\n * @param Integer $shop\r\n * @param Integer $movie\r\n * @return NULL\r\n */\r\n function drop($shop, $movie) {\r\n \r\n }\r\n \r\n /**\r\n * @return Integer[][]\r\n */\r\n function report() {\r\n \r\n }\r\n}\r\n\r\n/**\r\n * Your MovieRentingSystem object will be instantiated and called as such:\r\n * $obj = MovieRentingSystem($n, $entries);\r\n * $ret_1 = $obj->search($movie);\r\n * $obj->rent($shop, $movie);\r\n * $obj->drop($shop, $movie);\r\n * $ret_4 = $obj->report();\r\n */",
|
|
"__typename": "CodeSnippetNode"
|
|
},
|
|
{
|
|
"lang": "TypeScript",
|
|
"langSlug": "typescript",
|
|
"code": "class MovieRentingSystem {\r\n constructor(n: number, entries: number[][]) {\r\n\r\n }\r\n\r\n search(movie: number): number[] {\r\n\r\n }\r\n\r\n rent(shop: number, movie: number): void {\r\n\r\n }\r\n\r\n drop(shop: number, movie: number): void {\r\n\r\n }\r\n\r\n report(): number[][] {\r\n\r\n }\r\n}\r\n\r\n/**\r\n * Your MovieRentingSystem object will be instantiated and called as such:\r\n * var obj = new MovieRentingSystem(n, entries)\r\n * var param_1 = obj.search(movie)\r\n * obj.rent(shop,movie)\r\n * obj.drop(shop,movie)\r\n * var param_4 = obj.report()\r\n */",
|
|
"__typename": "CodeSnippetNode"
|
|
},
|
|
{
|
|
"lang": "Racket",
|
|
"langSlug": "racket",
|
|
"code": "(define movie-renting-system%\r\n (class object%\r\n (super-new)\r\n\r\n ; n : exact-integer?\r\n\r\n ; entries : (listof (listof exact-integer?))\r\n (init-field\r\n n\r\n entries)\r\n \r\n ; search : exact-integer? -> (listof exact-integer?)\r\n (define/public (search movie)\r\n\r\n )\r\n ; rent : exact-integer? exact-integer? -> void?\r\n (define/public (rent shop movie)\r\n\r\n )\r\n ; drop : exact-integer? exact-integer? -> void?\r\n (define/public (drop shop movie)\r\n\r\n )\r\n ; report : -> (listof (listof exact-integer?))\r\n (define/public (report)\r\n\r\n )))\r\n\r\n;; Your movie-renting-system% object will be instantiated and called as such:\r\n;; (define obj (new movie-renting-system% [n n] [entries entries]))\r\n;; (define param_1 (send obj search movie))\r\n;; (send obj rent shop movie)\r\n;; (send obj drop shop movie)\r\n;; (define param_4 (send obj report))",
|
|
"__typename": "CodeSnippetNode"
|
|
}
|
|
],
|
|
"stats": "{\"totalAccepted\": \"3.9K\", \"totalSubmission\": \"9.3K\", \"totalAcceptedRaw\": 3876, \"totalSubmissionRaw\": 9293, \"acRate\": \"41.7%\"}",
|
|
"hints": [
|
|
"You need to maintain a sorted list for each movie and a sorted list for rented movies",
|
|
"When renting a movie remove it from its movies sorted list and added it to the rented list and vice versa in the case of dropping a movie"
|
|
],
|
|
"solution": null,
|
|
"status": null,
|
|
"sampleTestCase": "[\"MovieRentingSystem\",\"search\",\"rent\",\"rent\",\"report\",\"drop\",\"search\"]\n[[3,[[0,1,5],[0,2,6],[0,3,7],[1,1,4],[1,2,7],[2,1,5]]],[1],[0,1],[1,2],[],[1,2],[2]]",
|
|
"metaData": "{\n \"classname\": \"MovieRentingSystem\",\n \"constructor\": {\n \"params\": [\n {\n \"type\": \"integer\",\n \"name\": \"n\"\n },\n {\n \"name\": \"entries\",\n \"type\": \"integer[][]\"\n }\n ]\n },\n \"methods\": [\n {\n \"params\": [\n {\n \"type\": \"integer\",\n \"name\": \"movie\"\n }\n ],\n \"name\": \"search\",\n \"return\": {\n \"type\": \"list<integer>\"\n }\n },\n {\n \"params\": [\n {\n \"type\": \"integer\",\n \"name\": \"shop\"\n },\n {\n \"type\": \"integer\",\n \"name\": \"movie\"\n }\n ],\n \"name\": \"rent\",\n \"return\": {\n \"type\": \"void\"\n }\n },\n {\n \"params\": [\n {\n \"type\": \"integer\",\n \"name\": \"shop\"\n },\n {\n \"type\": \"integer\",\n \"name\": \"movie\"\n }\n ],\n \"name\": \"drop\",\n \"return\": {\n \"type\": \"void\"\n }\n },\n {\n \"params\": [],\n \"name\": \"report\",\n \"return\": {\n \"type\": \"list<list<integer>>\"\n }\n }\n ],\n \"return\": {\n \"type\": \"boolean\"\n },\n \"systemdesign\": true,\n \"manual\": false\n}",
|
|
"judgerAvailable": true,
|
|
"judgeType": "large",
|
|
"mysqlSchemas": [],
|
|
"enableRunCode": true,
|
|
"enableTestMode": false,
|
|
"enableDebugger": true,
|
|
"envInfo": "{\"cpp\": [\"C++\", \"<p>Compiled with <code> clang 11 </code> using the latest C++ 17 standard.</p>\\r\\n\\r\\n<p>Your code is compiled with level two optimization (<code>-O2</code>). <a href=\\\"https://github.com/google/sanitizers/wiki/AddressSanitizer\\\" target=\\\"_blank\\\">AddressSanitizer</a> is also enabled to help detect out-of-bounds and use-after-free bugs.</p>\\r\\n\\r\\n<p>Most standard library headers are already included automatically for your convenience.</p>\"], \"java\": [\"Java\", \"<p><code> OpenJDK 17 </code>. Java 8 features such as lambda expressions and stream API can be used. </p>\\r\\n\\r\\n<p>Most standard library headers are already included automatically for your convenience.</p>\\r\\n<p>Includes <code>Pair</code> class from https://docs.oracle.com/javase/8/javafx/api/javafx/util/Pair.html.</p>\"], \"python\": [\"Python\", \"<p><code>Python 2.7.12</code>.</p>\\r\\n\\r\\n<p>Most libraries are already imported automatically for your convenience, such as <a href=\\\"https://docs.python.org/2/library/array.html\\\" target=\\\"_blank\\\">array</a>, <a href=\\\"https://docs.python.org/2/library/bisect.html\\\" target=\\\"_blank\\\">bisect</a>, <a href=\\\"https://docs.python.org/2/library/collections.html\\\" target=\\\"_blank\\\">collections</a>. If you need more libraries, you can import it yourself.</p>\\r\\n\\r\\n<p>For Map/TreeMap data structure, you may use <a href=\\\"http://www.grantjenks.com/docs/sortedcontainers/\\\" target=\\\"_blank\\\">sortedcontainers</a> library.</p>\\r\\n\\r\\n<p>Note that Python 2.7 <a href=\\\"https://www.python.org/dev/peps/pep-0373/\\\" target=\\\"_blank\\\">will not be maintained past 2020</a>. For the latest Python, please choose Python3 instead.</p>\"], \"c\": [\"C\", \"<p>Compiled with <code>gcc 8.2</code> using the gnu99 standard.</p>\\r\\n\\r\\n<p>Your code is compiled with level one optimization (<code>-O1</code>). <a href=\\\"https://github.com/google/sanitizers/wiki/AddressSanitizer\\\" target=\\\"_blank\\\">AddressSanitizer</a> is also enabled to help detect out-of-bounds and use-after-free bugs.</p>\\r\\n\\r\\n<p>Most standard library headers are already included automatically for your convenience.</p>\\r\\n\\r\\n<p>For hash table operations, you may use <a href=\\\"https://troydhanson.github.io/uthash/\\\" target=\\\"_blank\\\">uthash</a>. \\\"uthash.h\\\" is included by default. Below are some examples:</p>\\r\\n\\r\\n<p><b>1. Adding an item to a hash.</b>\\r\\n<pre>\\r\\nstruct hash_entry {\\r\\n int id; /* we'll use this field as the key */\\r\\n char name[10];\\r\\n UT_hash_handle hh; /* makes this structure hashable */\\r\\n};\\r\\n\\r\\nstruct hash_entry *users = NULL;\\r\\n\\r\\nvoid add_user(struct hash_entry *s) {\\r\\n HASH_ADD_INT(users, id, s);\\r\\n}\\r\\n</pre>\\r\\n</p>\\r\\n\\r\\n<p><b>2. Looking up an item in a hash:</b>\\r\\n<pre>\\r\\nstruct hash_entry *find_user(int user_id) {\\r\\n struct hash_entry *s;\\r\\n HASH_FIND_INT(users, &user_id, s);\\r\\n return s;\\r\\n}\\r\\n</pre>\\r\\n</p>\\r\\n\\r\\n<p><b>3. Deleting an item in a hash:</b>\\r\\n<pre>\\r\\nvoid delete_user(struct hash_entry *user) {\\r\\n HASH_DEL(users, user); \\r\\n}\\r\\n</pre>\\r\\n</p>\"], \"csharp\": [\"C#\", \"<p><a href=\\\"https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-9\\\" target=\\\"_blank\\\">C# 10 with .NET 6 runtime</a></p>\\r\\n\\r\\n<p>Your code is compiled with debug flag enabled (<code>/debug</code>).</p>\"], \"javascript\": [\"JavaScript\", \"<p><code>Node.js 16.13.2</code>.</p>\\r\\n\\r\\n<p>Your code is run with <code>--harmony</code> flag, enabling <a href=\\\"http://node.green/\\\" target=\\\"_blank\\\">new ES6 features</a>.</p>\\r\\n\\r\\n<p><a href=\\\"https://lodash.com\\\" target=\\\"_blank\\\">lodash.js</a> library is included by default.</p>\\r\\n\\r\\n<p>For Priority Queue / Queue data structures, you may use <a href=\\\"https://github.com/datastructures-js/priority-queue\\\" target=\\\"_blank\\\">datastructures-js/priority-queue</a> and <a href=\\\"https://github.com/datastructures-js/queue\\\" target=\\\"_blank\\\">datastructures-js/queue</a>.</p>\"], \"ruby\": [\"Ruby\", \"<p><code>Ruby 3.1</code></p>\\r\\n\\r\\n<p>Some common data structure implementations are provided in the Algorithms module: https://www.rubydoc.info/github/kanwei/algorithms/Algorithms</p>\"], \"swift\": [\"Swift\", \"<p><code>Swift 5.5.2</code>.</p>\"], \"golang\": [\"Go\", \"<p><code>Go 1.17.6</code>.</p>\\r\\n\\r\\n<p>Support <a href=\\\"https://godoc.org/github.com/emirpasic/gods\\\" target=\\\"_blank\\\">https://godoc.org/github.com/emirpasic/gods</a> library.</p>\"], \"python3\": [\"Python3\", \"<p><code>Python 3.10</code>.</p>\\r\\n\\r\\n<p>Most libraries are already imported automatically for your convenience, such as <a href=\\\"https://docs.python.org/3/library/array.html\\\" target=\\\"_blank\\\">array</a>, <a href=\\\"https://docs.python.org/3/library/bisect.html\\\" target=\\\"_blank\\\">bisect</a>, <a href=\\\"https://docs.python.org/3/library/collections.html\\\" target=\\\"_blank\\\">collections</a>. If you need more libraries, you can import it yourself.</p>\\r\\n\\r\\n<p>For Map/TreeMap data structure, you may use <a href=\\\"http://www.grantjenks.com/docs/sortedcontainers/\\\" target=\\\"_blank\\\">sortedcontainers</a> library.</p>\"], \"scala\": [\"Scala\", \"<p><code>Scala 2.13.7</code>.</p>\"], \"kotlin\": [\"Kotlin\", \"<p><code>Kotlin 1.3.10</code>.</p>\"], \"rust\": [\"Rust\", \"<p><code>Rust 1.58.1</code></p>\\r\\n\\r\\n<p>Supports <a href=\\\"https://crates.io/crates/rand\\\" target=\\\"_blank\\\">rand </a> v0.6\\u00a0from crates.io</p>\"], \"php\": [\"PHP\", \"<p><code>PHP 8.1</code>.</p>\\r\\n<p>With bcmath module</p>\"], \"typescript\": [\"Typescript\", \"<p><code>TypeScript 4.5.4, Node.js 16.13.2</code>.</p>\\r\\n\\r\\n<p>Your code is run with <code>--harmony</code> flag, enabling <a href=\\\"http://node.green/\\\" target=\\\"_blank\\\">new ES2020 features</a>.</p>\\r\\n\\r\\n<p><a href=\\\"https://lodash.com\\\" target=\\\"_blank\\\">lodash.js</a> library is included by default.</p>\"], \"racket\": [\"Racket\", \"<p>Run with <code>Racket 8.3</code>.</p>\"]}",
|
|
"libraryUrl": null,
|
|
"adminUrl": null,
|
|
"challengeQuestion": null,
|
|
"__typename": "QuestionNode"
|
|
}
|
|
}
|
|
} |