{
    "data": {
        "question": {
            "questionId": "2104",
            "questionFrontendId": "1993",
            "boundTopicId": null,
            "title": "Operations on Tree",
            "titleSlug": "operations-on-tree",
            "content": "<p>You are given a tree with <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> in the form of a parent array <code>parent</code> where <code>parent[i]</code> is the parent of the <code>i<sup>th</sup></code> node. The root of the tree is node <code>0</code>, so <code>parent[0] = -1</code> since it has no parent. You want to design a data structure that allows users to lock, unlock, and upgrade nodes in the tree.</p>\n\n<p>The data structure should support the following functions:</p>\n\n<ul>\n\t<li><strong>Lock:</strong> <strong>Locks</strong> the given node for the given user and prevents other users from locking the same node. You may only lock a node using this function if the node is unlocked.</li>\n\t<li><strong>Unlock: Unlocks</strong> the given node for the given user. You may only unlock a node using this function if it is currently locked by the same user.</li>\n\t<li><b>Upgrade</b><strong>: Locks</strong> the given node for the given user and <strong>unlocks</strong> all of its descendants <strong>regardless</strong> of who locked it. You may only upgrade a node if <strong>all</strong> 3 conditions are true:\n\t<ul>\n\t\t<li>The node is unlocked,</li>\n\t\t<li>It has at least one locked descendant (by <strong>any</strong> user), and</li>\n\t\t<li>It does not have any locked ancestors.</li>\n\t</ul>\n\t</li>\n</ul>\n\n<p>Implement the <code>LockingTree</code> class:</p>\n\n<ul>\n\t<li><code>LockingTree(int[] parent)</code> initializes the data structure with the parent array.</li>\n\t<li><code>lock(int num, int user)</code> returns <code>true</code> if it is possible for the user with id <code>user</code> to lock the node <code>num</code>, or <code>false</code> otherwise. If it is possible, the node <code>num</code> will become<strong> locked</strong> by the user with id <code>user</code>.</li>\n\t<li><code>unlock(int num, int user)</code> returns <code>true</code> if it is possible for the user with id <code>user</code> to unlock the node <code>num</code>, or <code>false</code> otherwise. If it is possible, the node <code>num</code> will become <strong>unlocked</strong>.</li>\n\t<li><code>upgrade(int num, int user)</code> returns <code>true</code> if it is possible for the user with id <code>user</code> to upgrade the node <code>num</code>, or <code>false</code> otherwise. If it is possible, the node <code>num</code> will be <strong>upgraded</strong>.</li>\n</ul>\n\n<p>&nbsp;</p>\n<p><strong>Example 1:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/07/29/untitled.png\" style=\"width: 375px; height: 246px;\" />\n<pre>\n<strong>Input</strong>\n[&quot;LockingTree&quot;, &quot;lock&quot;, &quot;unlock&quot;, &quot;unlock&quot;, &quot;lock&quot;, &quot;upgrade&quot;, &quot;lock&quot;]\n[[[-1, 0, 0, 1, 1, 2, 2]], [2, 2], [2, 3], [2, 2], [4, 5], [0, 1], [0, 1]]\n<strong>Output</strong>\n[null, true, false, true, true, true, false]\n\n<strong>Explanation</strong>\nLockingTree lockingTree = new LockingTree([-1, 0, 0, 1, 1, 2, 2]);\nlockingTree.lock(2, 2);    // return true because node 2 is unlocked.\n                           // Node 2 will now be locked by user 2.\nlockingTree.unlock(2, 3);  // return false because user 3 cannot unlock a node locked by user 2.\nlockingTree.unlock(2, 2);  // return true because node 2 was previously locked by user 2.\n                           // Node 2 will now be unlocked.\nlockingTree.lock(4, 5);    // return true because node 4 is unlocked.\n                           // Node 4 will now be locked by user 5.\nlockingTree.upgrade(0, 1); // return true because node 0 is unlocked and has at least one locked descendant (node 4).\n                           // Node 0 will now be locked by user 1 and node 4 will now be unlocked.\nlockingTree.lock(0, 1);    // return false because node 0 is already locked.\n</pre>\n\n<p>&nbsp;</p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>n == parent.length</code></li>\n\t<li><code>2 &lt;= n &lt;= 2000</code></li>\n\t<li><code>0 &lt;= parent[i] &lt;= n - 1</code> for <code>i != 0</code></li>\n\t<li><code>parent[0] == -1</code></li>\n\t<li><code>0 &lt;= num &lt;= n - 1</code></li>\n\t<li><code>1 &lt;= user &lt;= 10<sup>4</sup></code></li>\n\t<li><code>parent</code> represents a valid tree.</li>\n\t<li>At most <code>2000</code> calls <strong>in total</strong> will be made to <code>lock</code>, <code>unlock</code>, and <code>upgrade</code>.</li>\n</ul>\n",
            "translatedTitle": null,
            "translatedContent": null,
            "isPaidOnly": false,
            "difficulty": "Medium",
            "likes": 201,
            "dislikes": 35,
            "isLiked": null,
            "similarQuestions": "[{\"title\": \"Throne Inheritance\", \"titleSlug\": \"throne-inheritance\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
            "exampleTestcases": "[\"LockingTree\",\"lock\",\"unlock\",\"unlock\",\"lock\",\"upgrade\",\"lock\"]\n[[[-1,0,0,1,1,2,2]],[2,2],[2,3],[2,2],[4,5],[0,1],[0,1]]",
            "categoryTitle": "Algorithms",
            "contributors": [],
            "topicTags": [
                {
                    "name": "Hash Table",
                    "slug": "hash-table",
                    "translatedName": null,
                    "__typename": "TopicTagNode"
                },
                {
                    "name": "Tree",
                    "slug": "tree",
                    "translatedName": null,
                    "__typename": "TopicTagNode"
                },
                {
                    "name": "Breadth-First Search",
                    "slug": "breadth-first-search",
                    "translatedName": null,
                    "__typename": "TopicTagNode"
                },
                {
                    "name": "Design",
                    "slug": "design",
                    "translatedName": null,
                    "__typename": "TopicTagNode"
                }
            ],
            "companyTagStats": null,
            "codeSnippets": [
                {
                    "lang": "C++",
                    "langSlug": "cpp",
                    "code": "class LockingTree {\npublic:\n    LockingTree(vector<int>& parent) {\n        \n    }\n    \n    bool lock(int num, int user) {\n        \n    }\n    \n    bool unlock(int num, int user) {\n        \n    }\n    \n    bool upgrade(int num, int user) {\n        \n    }\n};\n\n/**\n * Your LockingTree object will be instantiated and called as such:\n * LockingTree* obj = new LockingTree(parent);\n * bool param_1 = obj->lock(num,user);\n * bool param_2 = obj->unlock(num,user);\n * bool param_3 = obj->upgrade(num,user);\n */",
                    "__typename": "CodeSnippetNode"
                },
                {
                    "lang": "Java",
                    "langSlug": "java",
                    "code": "class LockingTree {\n\n    public LockingTree(int[] parent) {\n        \n    }\n    \n    public boolean lock(int num, int user) {\n        \n    }\n    \n    public boolean unlock(int num, int user) {\n        \n    }\n    \n    public boolean upgrade(int num, int user) {\n        \n    }\n}\n\n/**\n * Your LockingTree object will be instantiated and called as such:\n * LockingTree obj = new LockingTree(parent);\n * boolean param_1 = obj.lock(num,user);\n * boolean param_2 = obj.unlock(num,user);\n * boolean param_3 = obj.upgrade(num,user);\n */",
                    "__typename": "CodeSnippetNode"
                },
                {
                    "lang": "Python",
                    "langSlug": "python",
                    "code": "class LockingTree(object):\n\n    def __init__(self, parent):\n        \"\"\"\n        :type parent: List[int]\n        \"\"\"\n        \n\n    def lock(self, num, user):\n        \"\"\"\n        :type num: int\n        :type user: int\n        :rtype: bool\n        \"\"\"\n        \n\n    def unlock(self, num, user):\n        \"\"\"\n        :type num: int\n        :type user: int\n        :rtype: bool\n        \"\"\"\n        \n\n    def upgrade(self, num, user):\n        \"\"\"\n        :type num: int\n        :type user: int\n        :rtype: bool\n        \"\"\"\n        \n\n\n# Your LockingTree object will be instantiated and called as such:\n# obj = LockingTree(parent)\n# param_1 = obj.lock(num,user)\n# param_2 = obj.unlock(num,user)\n# param_3 = obj.upgrade(num,user)",
                    "__typename": "CodeSnippetNode"
                },
                {
                    "lang": "Python3",
                    "langSlug": "python3",
                    "code": "class LockingTree:\n\n    def __init__(self, parent: List[int]):\n        \n\n    def lock(self, num: int, user: int) -> bool:\n        \n\n    def unlock(self, num: int, user: int) -> bool:\n        \n\n    def upgrade(self, num: int, user: int) -> bool:\n        \n\n\n# Your LockingTree object will be instantiated and called as such:\n# obj = LockingTree(parent)\n# param_1 = obj.lock(num,user)\n# param_2 = obj.unlock(num,user)\n# param_3 = obj.upgrade(num,user)",
                    "__typename": "CodeSnippetNode"
                },
                {
                    "lang": "C",
                    "langSlug": "c",
                    "code": "\n\n\ntypedef struct {\n    \n} LockingTree;\n\n\nLockingTree* lockingTreeCreate(int* parent, int parentSize) {\n    \n}\n\nbool lockingTreeLock(LockingTree* obj, int num, int user) {\n  \n}\n\nbool lockingTreeUnlock(LockingTree* obj, int num, int user) {\n  \n}\n\nbool lockingTreeUpgrade(LockingTree* obj, int num, int user) {\n  \n}\n\nvoid lockingTreeFree(LockingTree* obj) {\n    \n}\n\n/**\n * Your LockingTree struct will be instantiated and called as such:\n * LockingTree* obj = lockingTreeCreate(parent, parentSize);\n * bool param_1 = lockingTreeLock(obj, num, user);\n \n * bool param_2 = lockingTreeUnlock(obj, num, user);\n \n * bool param_3 = lockingTreeUpgrade(obj, num, user);\n \n * lockingTreeFree(obj);\n*/",
                    "__typename": "CodeSnippetNode"
                },
                {
                    "lang": "C#",
                    "langSlug": "csharp",
                    "code": "public class LockingTree {\n\n    public LockingTree(int[] parent) {\n        \n    }\n    \n    public bool Lock(int num, int user) {\n        \n    }\n    \n    public bool Unlock(int num, int user) {\n        \n    }\n    \n    public bool Upgrade(int num, int user) {\n        \n    }\n}\n\n/**\n * Your LockingTree object will be instantiated and called as such:\n * LockingTree obj = new LockingTree(parent);\n * bool param_1 = obj.Lock(num,user);\n * bool param_2 = obj.Unlock(num,user);\n * bool param_3 = obj.Upgrade(num,user);\n */",
                    "__typename": "CodeSnippetNode"
                },
                {
                    "lang": "JavaScript",
                    "langSlug": "javascript",
                    "code": "/**\n * @param {number[]} parent\n */\nvar LockingTree = function(parent) {\n    \n};\n\n/** \n * @param {number} num \n * @param {number} user\n * @return {boolean}\n */\nLockingTree.prototype.lock = function(num, user) {\n    \n};\n\n/** \n * @param {number} num \n * @param {number} user\n * @return {boolean}\n */\nLockingTree.prototype.unlock = function(num, user) {\n    \n};\n\n/** \n * @param {number} num \n * @param {number} user\n * @return {boolean}\n */\nLockingTree.prototype.upgrade = function(num, user) {\n    \n};\n\n/** \n * Your LockingTree object will be instantiated and called as such:\n * var obj = new LockingTree(parent)\n * var param_1 = obj.lock(num,user)\n * var param_2 = obj.unlock(num,user)\n * var param_3 = obj.upgrade(num,user)\n */",
                    "__typename": "CodeSnippetNode"
                },
                {
                    "lang": "Ruby",
                    "langSlug": "ruby",
                    "code": "class LockingTree\n\n=begin\n    :type parent: Integer[]\n=end\n    def initialize(parent)\n        \n    end\n\n\n=begin\n    :type num: Integer\n    :type user: Integer\n    :rtype: Boolean\n=end\n    def lock(num, user)\n        \n    end\n\n\n=begin\n    :type num: Integer\n    :type user: Integer\n    :rtype: Boolean\n=end\n    def unlock(num, user)\n        \n    end\n\n\n=begin\n    :type num: Integer\n    :type user: Integer\n    :rtype: Boolean\n=end\n    def upgrade(num, user)\n        \n    end\n\n\nend\n\n# Your LockingTree object will be instantiated and called as such:\n# obj = LockingTree.new(parent)\n# param_1 = obj.lock(num, user)\n# param_2 = obj.unlock(num, user)\n# param_3 = obj.upgrade(num, user)",
                    "__typename": "CodeSnippetNode"
                },
                {
                    "lang": "Swift",
                    "langSlug": "swift",
                    "code": "\nclass LockingTree {\n\n    init(_ parent: [Int]) {\n        \n    }\n    \n    func lock(_ num: Int, _ user: Int) -> Bool {\n        \n    }\n    \n    func unlock(_ num: Int, _ user: Int) -> Bool {\n        \n    }\n    \n    func upgrade(_ num: Int, _ user: Int) -> Bool {\n        \n    }\n}\n\n/**\n * Your LockingTree object will be instantiated and called as such:\n * let obj = LockingTree(parent)\n * let ret_1: Bool = obj.lock(num, user)\n * let ret_2: Bool = obj.unlock(num, user)\n * let ret_3: Bool = obj.upgrade(num, user)\n */",
                    "__typename": "CodeSnippetNode"
                },
                {
                    "lang": "Go",
                    "langSlug": "golang",
                    "code": "type LockingTree struct {\n    \n}\n\n\nfunc Constructor(parent []int) LockingTree {\n    \n}\n\n\nfunc (this *LockingTree) Lock(num int, user int) bool {\n    \n}\n\n\nfunc (this *LockingTree) Unlock(num int, user int) bool {\n    \n}\n\n\nfunc (this *LockingTree) Upgrade(num int, user int) bool {\n    \n}\n\n\n/**\n * Your LockingTree object will be instantiated and called as such:\n * obj := Constructor(parent);\n * param_1 := obj.Lock(num,user);\n * param_2 := obj.Unlock(num,user);\n * param_3 := obj.Upgrade(num,user);\n */",
                    "__typename": "CodeSnippetNode"
                },
                {
                    "lang": "Scala",
                    "langSlug": "scala",
                    "code": "class LockingTree(_parent: Array[Int]) {\n\n    def lock(num: Int, user: Int): Boolean = {\n        \n    }\n\n    def unlock(num: Int, user: Int): Boolean = {\n        \n    }\n\n    def upgrade(num: Int, user: Int): Boolean = {\n        \n    }\n\n}\n\n/**\n * Your LockingTree object will be instantiated and called as such:\n * var obj = new LockingTree(parent)\n * var param_1 = obj.lock(num,user)\n * var param_2 = obj.unlock(num,user)\n * var param_3 = obj.upgrade(num,user)\n */",
                    "__typename": "CodeSnippetNode"
                },
                {
                    "lang": "Kotlin",
                    "langSlug": "kotlin",
                    "code": "class LockingTree(parent: IntArray) {\n\n    fun lock(num: Int, user: Int): Boolean {\n        \n    }\n\n    fun unlock(num: Int, user: Int): Boolean {\n        \n    }\n\n    fun upgrade(num: Int, user: Int): Boolean {\n        \n    }\n\n}\n\n/**\n * Your LockingTree object will be instantiated and called as such:\n * var obj = LockingTree(parent)\n * var param_1 = obj.lock(num,user)\n * var param_2 = obj.unlock(num,user)\n * var param_3 = obj.upgrade(num,user)\n */",
                    "__typename": "CodeSnippetNode"
                },
                {
                    "lang": "Rust",
                    "langSlug": "rust",
                    "code": "struct LockingTree {\n\n}\n\n\n/** \n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl LockingTree {\n\n    fn new(parent: Vec<i32>) -> Self {\n        \n    }\n    \n    fn lock(&self, num: i32, user: i32) -> bool {\n        \n    }\n    \n    fn unlock(&self, num: i32, user: i32) -> bool {\n        \n    }\n    \n    fn upgrade(&self, num: i32, user: i32) -> bool {\n        \n    }\n}\n\n/**\n * Your LockingTree object will be instantiated and called as such:\n * let obj = LockingTree::new(parent);\n * let ret_1: bool = obj.lock(num, user);\n * let ret_2: bool = obj.unlock(num, user);\n * let ret_3: bool = obj.upgrade(num, user);\n */",
                    "__typename": "CodeSnippetNode"
                },
                {
                    "lang": "PHP",
                    "langSlug": "php",
                    "code": "class LockingTree {\n    /**\n     * @param Integer[] $parent\n     */\n    function __construct($parent) {\n        \n    }\n  \n    /**\n     * @param Integer $num\n     * @param Integer $user\n     * @return Boolean\n     */\n    function lock($num, $user) {\n        \n    }\n  \n    /**\n     * @param Integer $num\n     * @param Integer $user\n     * @return Boolean\n     */\n    function unlock($num, $user) {\n        \n    }\n  \n    /**\n     * @param Integer $num\n     * @param Integer $user\n     * @return Boolean\n     */\n    function upgrade($num, $user) {\n        \n    }\n}\n\n/**\n * Your LockingTree object will be instantiated and called as such:\n * $obj = LockingTree($parent);\n * $ret_1 = $obj->lock($num, $user);\n * $ret_2 = $obj->unlock($num, $user);\n * $ret_3 = $obj->upgrade($num, $user);\n */",
                    "__typename": "CodeSnippetNode"
                },
                {
                    "lang": "TypeScript",
                    "langSlug": "typescript",
                    "code": "class LockingTree {\n    constructor(parent: number[]) {\n\n    }\n\n    lock(num: number, user: number): boolean {\n\n    }\n\n    unlock(num: number, user: number): boolean {\n\n    }\n\n    upgrade(num: number, user: number): boolean {\n\n    }\n}\n\n/**\n * Your LockingTree object will be instantiated and called as such:\n * var obj = new LockingTree(parent)\n * var param_1 = obj.lock(num,user)\n * var param_2 = obj.unlock(num,user)\n * var param_3 = obj.upgrade(num,user)\n */",
                    "__typename": "CodeSnippetNode"
                },
                {
                    "lang": "Racket",
                    "langSlug": "racket",
                    "code": "(define locking-tree%\n  (class object%\n    (super-new)\n\n    ; parent : (listof exact-integer?)\n    (init-field\n      parent)\n    \n    ; lock : exact-integer? exact-integer? -> boolean?\n    (define/public (lock num user)\n\n      )\n    ; unlock : exact-integer? exact-integer? -> boolean?\n    (define/public (unlock num user)\n\n      )\n    ; upgrade : exact-integer? exact-integer? -> boolean?\n    (define/public (upgrade num user)\n\n      )))\n\n;; Your locking-tree% object will be instantiated and called as such:\n;; (define obj (new locking-tree% [parent parent]))\n;; (define param_1 (send obj lock num user))\n;; (define param_2 (send obj unlock num user))\n;; (define param_3 (send obj upgrade num user))",
                    "__typename": "CodeSnippetNode"
                },
                {
                    "lang": "Erlang",
                    "langSlug": "erlang",
                    "code": "-spec locking_tree_init_(Parent :: [integer()]) -> any().\nlocking_tree_init_(Parent) ->\n  .\n\n-spec locking_tree_lock(Num :: integer(), User :: integer()) -> boolean().\nlocking_tree_lock(Num, User) ->\n  .\n\n-spec locking_tree_unlock(Num :: integer(), User :: integer()) -> boolean().\nlocking_tree_unlock(Num, User) ->\n  .\n\n-spec locking_tree_upgrade(Num :: integer(), User :: integer()) -> boolean().\nlocking_tree_upgrade(Num, User) ->\n  .\n\n\n%% Your functions will be called as such:\n%% locking_tree_init_(Parent),\n%% Param_1 = locking_tree_lock(Num, User),\n%% Param_2 = locking_tree_unlock(Num, User),\n%% Param_3 = locking_tree_upgrade(Num, User),\n\n%% locking_tree_init_ will be called before every test case, in which you can do some necessary initializations.",
                    "__typename": "CodeSnippetNode"
                },
                {
                    "lang": "Elixir",
                    "langSlug": "elixir",
                    "code": "defmodule LockingTree do\n  @spec init_(parent :: [integer]) :: any\n  def init_(parent) do\n\n  end\n\n  @spec lock(num :: integer, user :: integer) :: boolean\n  def lock(num, user) do\n\n  end\n\n  @spec unlock(num :: integer, user :: integer) :: boolean\n  def unlock(num, user) do\n\n  end\n\n  @spec upgrade(num :: integer, user :: integer) :: boolean\n  def upgrade(num, user) do\n\n  end\nend\n\n# Your functions will be called as such:\n# LockingTree.init_(parent)\n# param_1 = LockingTree.lock(num, user)\n# param_2 = LockingTree.unlock(num, user)\n# param_3 = LockingTree.upgrade(num, user)\n\n# LockingTree.init_ will be called before every test case, in which you can do some necessary initializations.",
                    "__typename": "CodeSnippetNode"
                }
            ],
            "stats": "{\"totalAccepted\": \"6.5K\", \"totalSubmission\": \"15.4K\", \"totalAcceptedRaw\": 6463, \"totalSubmissionRaw\": 15386, \"acRate\": \"42.0%\"}",
            "hints": [
                "How can we use the small constraints to help us solve the problem?",
                "How can we traverse the ancestors and descendants of a node?"
            ],
            "solution": null,
            "status": null,
            "sampleTestCase": "[\"LockingTree\",\"lock\",\"unlock\",\"unlock\",\"lock\",\"upgrade\",\"lock\"]\n[[[-1,0,0,1,1,2,2]],[2,2],[2,3],[2,2],[4,5],[0,1],[0,1]]",
            "metaData": "{\n  \"classname\": \"LockingTree\",\n  \"constructor\": {\n    \"params\": [\n      {\n        \"type\": \"integer[]\",\n        \"name\": \"parent\"\n      }\n    ]\n  },\n  \"methods\": [\n    {\n      \"params\": [\n        {\n          \"type\": \"integer\",\n          \"name\": \"num\"\n        },\n        {\n          \"type\": \"integer\",\n          \"name\": \"user\"\n        }\n      ],\n      \"name\": \"lock\",\n      \"return\": {\n        \"type\": \"boolean\"\n      }\n    },\n    {\n      \"params\": [\n        {\n          \"type\": \"integer\",\n          \"name\": \"num\"\n        },\n        {\n          \"type\": \"integer\",\n          \"name\": \"user\"\n        }\n      ],\n      \"name\": \"unlock\",\n      \"return\": {\n        \"type\": \"boolean\"\n      }\n    },\n    {\n      \"params\": [\n        {\n          \"type\": \"integer\",\n          \"name\": \"num\"\n        },\n        {\n          \"type\": \"integer\",\n          \"name\": \"user\"\n        }\n      ],\n      \"name\": \"upgrade\",\n      \"return\": {\n        \"type\": \"boolean\"\n      }\n    }\n  ],\n  \"return\": {\n    \"type\": \"boolean\"\n  },\n  \"systemdesign\": true\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>\"], \"erlang\": [\"Erlang\", \"Erlang/OTP 24.2\"], \"elixir\": [\"Elixir\", \"Elixir 1.13.0 with Erlang/OTP 24.2\"]}",
            "libraryUrl": null,
            "adminUrl": null,
            "challengeQuestion": null,
            "__typename": "QuestionNode"
        }
    }
}