{ "data": { "question": { "questionId": "2023", "questionFrontendId": "1912", "boundTopicId": null, "title": "Design Movie Rental System", "titleSlug": "design-movie-rental-system", "content": "

You have a movie renting company consisting of n 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.

\r\n\r\n

Each movie is given as a 2D integer array entries where entries[i] = [shopi, moviei, pricei] indicates that there is a copy of movie moviei at shop shopi with a rental price of pricei. Each shop carries at most one copy of a movie moviei.

\r\n\r\n

The system should support the following functions:

\r\n\r\n\r\n\r\n

Implement the MovieRentingSystem class:

\r\n\r\n\r\n\r\n

Note: The test cases will be generated such that rent will only be called if the shop has an unrented copy of the movie, and drop will only be called if the shop had previously rented out the movie.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput\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\nOutput\r\n[null, [1, 0, 2], null, null, [[0, 1], [1, 2]], null, [0, 1]]\r\n\r\nExplanation\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
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n", "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>& entries) {\r\n \r\n }\r\n \r\n vector 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> 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 param_1 = obj->search(movie);\r\n * obj->rent(shop,movie);\r\n * obj->drop(shop,movie);\r\n * vector> 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 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> 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 param_1 = obj.search(movie);\r\n * obj.rent(shop,movie);\r\n * obj.drop(shop,movie);\r\n * List> 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 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> 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 param_1 = obj.Search(movie);\r\n * obj.Rent(shop,movie);\r\n * obj.Drop(shop,movie);\r\n * IList> 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) {\r\n\r\n fun search(movie: Int): List {\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> {\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>) -> Self {\r\n \r\n }\r\n \r\n fn search(&self, movie: i32) -> Vec {\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> {\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 = obj.search(movie);\r\n * obj.rent(shop, movie);\r\n * obj.drop(shop, movie);\r\n * let ret_4: Vec> = 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\"\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>\"\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++\", \"

Compiled with clang 11 using the latest C++ 17 standard.

\\r\\n\\r\\n

Your code is compiled with level two optimization (-O2). AddressSanitizer is also enabled to help detect out-of-bounds and use-after-free bugs.

\\r\\n\\r\\n

Most standard library headers are already included automatically for your convenience.

\"], \"java\": [\"Java\", \"

OpenJDK 17 . Java 8 features such as lambda expressions and stream API can be used.

\\r\\n\\r\\n

Most standard library headers are already included automatically for your convenience.

\\r\\n

Includes Pair class from https://docs.oracle.com/javase/8/javafx/api/javafx/util/Pair.html.

\"], \"python\": [\"Python\", \"

Python 2.7.12.

\\r\\n\\r\\n

Most libraries are already imported automatically for your convenience, such as array, bisect, collections. If you need more libraries, you can import it yourself.

\\r\\n\\r\\n

For Map/TreeMap data structure, you may use sortedcontainers library.

\\r\\n\\r\\n

Note that Python 2.7 will not be maintained past 2020. For the latest Python, please choose Python3 instead.

\"], \"c\": [\"C\", \"

Compiled with gcc 8.2 using the gnu99 standard.

\\r\\n\\r\\n

Your code is compiled with level one optimization (-O1). AddressSanitizer is also enabled to help detect out-of-bounds and use-after-free bugs.

\\r\\n\\r\\n

Most standard library headers are already included automatically for your convenience.

\\r\\n\\r\\n

For hash table operations, you may use uthash. \\\"uthash.h\\\" is included by default. Below are some examples:

\\r\\n\\r\\n

1. Adding an item to a hash.\\r\\n

\\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
\\r\\n

\\r\\n\\r\\n

2. Looking up an item in a hash:\\r\\n

\\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
\\r\\n

\\r\\n\\r\\n

3. Deleting an item in a hash:\\r\\n

\\r\\nvoid delete_user(struct hash_entry *user) {\\r\\n    HASH_DEL(users, user);  \\r\\n}\\r\\n
\\r\\n

\"], \"csharp\": [\"C#\", \"

C# 10 with .NET 6 runtime

\\r\\n\\r\\n

Your code is compiled with debug flag enabled (/debug).

\"], \"javascript\": [\"JavaScript\", \"

Node.js 16.13.2.

\\r\\n\\r\\n

Your code is run with --harmony flag, enabling new ES6 features.

\\r\\n\\r\\n

lodash.js library is included by default.

\\r\\n\\r\\n

For Priority Queue / Queue data structures, you may use datastructures-js/priority-queue and datastructures-js/queue.

\"], \"ruby\": [\"Ruby\", \"

Ruby 3.1

\\r\\n\\r\\n

Some common data structure implementations are provided in the Algorithms module: https://www.rubydoc.info/github/kanwei/algorithms/Algorithms

\"], \"swift\": [\"Swift\", \"

Swift 5.5.2.

\"], \"golang\": [\"Go\", \"

Go 1.17.6.

\\r\\n\\r\\n

Support https://godoc.org/github.com/emirpasic/gods library.

\"], \"python3\": [\"Python3\", \"

Python 3.10.

\\r\\n\\r\\n

Most libraries are already imported automatically for your convenience, such as array, bisect, collections. If you need more libraries, you can import it yourself.

\\r\\n\\r\\n

For Map/TreeMap data structure, you may use sortedcontainers library.

\"], \"scala\": [\"Scala\", \"

Scala 2.13.7.

\"], \"kotlin\": [\"Kotlin\", \"

Kotlin 1.3.10.

\"], \"rust\": [\"Rust\", \"

Rust 1.58.1

\\r\\n\\r\\n

Supports rand v0.6\\u00a0from crates.io

\"], \"php\": [\"PHP\", \"

PHP 8.1.

\\r\\n

With bcmath module

\"], \"typescript\": [\"Typescript\", \"

TypeScript 4.5.4, Node.js 16.13.2.

\\r\\n\\r\\n

Your code is run with --harmony flag, enabling new ES2020 features.

\\r\\n\\r\\n

lodash.js library is included by default.

\"], \"racket\": [\"Racket\", \"

Run with Racket 8.3.

\"]}", "libraryUrl": null, "adminUrl": null, "challengeQuestion": null, "__typename": "QuestionNode" } } }