Operations on Tree
<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>

<p>The data structure should support the following functions:</p>

<ul>
	<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>
	<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>
	<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:
	<ul>
		<li>The node is unlocked,</li>
		<li>It has at least one locked descendant (by <strong>any</strong> user), and</li>
		<li>It does not have any locked ancestors.</li>
	</ul>
	</li>
</ul>

<p>Implement the <code>LockingTree</code> class:</p>

<ul>
	<li><code>LockingTree(int[] parent)</code> initializes the data structure with the parent array.</li>
	<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>
	<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>
	<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>
</ul>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/07/29/untitled.png" style="width: 375px; height: 246px;" />
<pre>
<strong>Input</strong>
[&quot;LockingTree&quot;, &quot;lock&quot;, &quot;unlock&quot;, &quot;unlock&quot;, &quot;lock&quot;, &quot;upgrade&quot;, &quot;lock&quot;]
[[[-1, 0, 0, 1, 1, 2, 2]], [2, 2], [2, 3], [2, 2], [4, 5], [0, 1], [0, 1]]
<strong>Output</strong>
[null, true, false, true, true, true, false]

<strong>Explanation</strong>
LockingTree lockingTree = new LockingTree([-1, 0, 0, 1, 1, 2, 2]);
lockingTree.lock(2, 2);    // return true because node 2 is unlocked.
                           // Node 2 will now be locked by user 2.
lockingTree.unlock(2, 3);  // return false because user 3 cannot unlock a node locked by user 2.
lockingTree.unlock(2, 2);  // return true because node 2 was previously locked by user 2.
                           // Node 2 will now be unlocked.
lockingTree.lock(4, 5);    // return true because node 4 is unlocked.
                           // Node 4 will now be locked by user 5.
lockingTree.upgrade(0, 1); // return true because node 0 is unlocked and has at least one locked descendant (node 4).
                           // Node 0 will now be locked by user 1 and node 4 will now be unlocked.
lockingTree.lock(0, 1);    // return false because node 0 is already locked.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>n == parent.length</code></li>
	<li><code>2 &lt;= n &lt;= 2000</code></li>
	<li><code>0 &lt;= parent[i] &lt;= n - 1</code> for <code>i != 0</code></li>
	<li><code>parent[0] == -1</code></li>
	<li><code>0 &lt;= num &lt;= n - 1</code></li>
	<li><code>1 &lt;= user &lt;= 10<sup>4</sup></code></li>
	<li><code>parent</code> represents a valid tree.</li>
	<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>
</ul>

['throne-inheritance']
[]
[{"value": "cpp", "text": "C++", "defaultCode": "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 */"}, {"value": "java", "text": "Java", "defaultCode": "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 */"}, {"value": "python", "text": "Python", "defaultCode": "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)"}, {"value": "python3", "text": "Python3", "defaultCode": "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)"}, {"value": "c", "text": "C", "defaultCode": "\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*/"}, {"value": "csharp", "text": "C#", "defaultCode": "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 */"}, {"value": "javascript", "text": "JavaScript", "defaultCode": "/**\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 */"}, {"value": "typescript", "text": "TypeScript", "defaultCode": "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 */"}, {"value": "php", "text": "PHP", "defaultCode": "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 */"}, {"value": "swift", "text": "Swift", "defaultCode": "\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 */"}, {"value": "kotlin", "text": "Kotlin", "defaultCode": "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 */"}, {"value": "dart", "text": "Dart", "defaultCode": "class LockingTree {\n\n  LockingTree(List<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 = LockingTree(parent);\n * bool param1 = obj.lock(num,user);\n * bool param2 = obj.unlock(num,user);\n * bool param3 = obj.upgrade(num,user);\n */"}, {"value": "golang", "text": "Go", "defaultCode": "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 */"}, {"value": "ruby", "text": "Ruby", "defaultCode": "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)"}, {"value": "scala", "text": "Scala", "defaultCode": "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 * val obj = new LockingTree(parent)\n * val param_1 = obj.lock(num,user)\n * val param_2 = obj.unlock(num,user)\n * val param_3 = obj.upgrade(num,user)\n */"}, {"value": "rust", "text": "Rust", "defaultCode": "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 */"}, {"value": "racket", "text": "Racket", "defaultCode": "(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    ; unlock : exact-integer? exact-integer? -> boolean?\n    (define/public (unlock num user)\n      )\n    ; upgrade : exact-integer? exact-integer? -> boolean?\n    (define/public (upgrade num user)\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))"}, {"value": "erlang", "text": "Erlang", "defaultCode": "-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."}, {"value": "elixir", "text": "Elixir", "defaultCode": "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."}]
{
  "classname": "LockingTree",
  "constructor": {
    "params": [
      {
        "type": "integer[]",
        "name": "parent"
      }
    ]
  },
  "methods": [
    {
      "params": [
        {
          "type": "integer",
          "name": "num"
        },
        {
          "type": "integer",
          "name": "user"
        }
      ],
      "name": "lock",
      "return": {
        "type": "boolean"
      }
    },
    {
      "params": [
        {
          "type": "integer",
          "name": "num"
        },
        {
          "type": "integer",
          "name": "user"
        }
      ],
      "name": "unlock",
      "return": {
        "type": "boolean"
      }
    },
    {
      "params": [
        {
          "type": "integer",
          "name": "num"
        },
        {
          "type": "integer",
          "name": "user"
        }
      ],
      "name": "upgrade",
      "return": {
        "type": "boolean"
      }
    }
  ],
  "return": {
    "type": "boolean"
  },
  "systemdesign": true
}
{"cpp": ["C++", "<p>Compiled with <code> clang 19 </code> using the latest C++ 23 standard, and <code>libstdc++</code> provided by GCC 14.</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 21</code>. Using compile arguments: <code>--enable-preview --release 21</code></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.18</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\">is not maintained anymore</a>. For the latest Python, please choose Python3 instead.</p>"], "c": ["C", "<p>Compiled with <code>gcc 14</code> using the gnu11 standard.</p>\r\n\r\n<p>Your code is compiled with level one 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>\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://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-13\" target=\"_blank\">C# 13</a> with .NET 9 runtime</p>"], "javascript": ["JavaScript", "<p><code>Node.js 22.14.0</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 6.3.2 version of <a href=\"https://github.com/datastructures-js/priority-queue/tree/v6.3.2\" target=\"_blank\">datastructures-js/priority-queue</a> and 4.2.3 version of <a href=\"https://github.com/datastructures-js/queue/tree/v4.2.3\" target=\"_blank\">datastructures-js/queue</a> and 1.0.4 version of <a href=\"https://github.com/datastructures-js/deque/tree/v1.0.4\" target=\"_blank\">datastructures-js/deque</a>.</p>"], "ruby": ["Ruby", "<p><code>Ruby 3.2</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 6.0</code>.</p>\r\n\r\n<p>You may use the following packages:<br/>\r\n<a href=\"https://github.com/apple/swift-algorithms/tree/1.2.0\" target=\"_blank\">swift-algorithms 1.2.0</a><br/>\r\n<a href=\"https://github.com/apple/swift-collections/tree/1.1.4\" target=\"_blank\">swift-collections 1.1.4</a><br/>\r\n<a href=\"https://github.com/apple/swift-numerics/tree/1.0.2\" target=\"_blank\">swift-numerics 1.0.2</a></p>"], "golang": ["Go", "<p><code>Go 1.23</code></p>\r\n<p>Support <a href=\"https://pkg.go.dev/github.com/emirpasic/gods@v1.18.1\" target=\"_blank\">https://pkg.go.dev/github.com/emirpasic/gods@v1.18.1</a> and <a href=\"https://pkg.go.dev/github.com/emirpasic/gods/v2@v2.0.0-alpha\" target=\"_blank\">https://pkg.go.dev/github.com/emirpasic/gods/v2@v2.0.0-alpha</a> library.</p>"], "python3": ["Python3", "<p><code>Python 3.11</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 3.3.1</code>.</p>"], "kotlin": ["Kotlin", "<p><code>Kotlin 2.1.10</code>.</p>"], "rust": ["Rust", "<p><code>Rust 1.85.0</code>. Your code will be compiled with <code>opt-level</code> 2.</p>\r\n\r\n<p>Supports <a href=\"https://crates.io/crates/rand\" target=\"_blank\">rand v0.8</a> and <a href=\"https://crates.io/crates/regex\" target=\"_blank\">regex\u00a0v1</a> and <a href=\"https://crates.io/crates/itertools\" target=\"_blank\">itertools\u00a0v0.14</a> from crates.io</p>"], "php": ["PHP", "<p><code>PHP 8.2</code>.</p>\r\n<p>With bcmath module</p>"], "typescript": ["Typescript", "<p><code>TypeScript 5.7.3, Node.js 22.14.0</code>.</p>\r\n\r\n<p>Compile Options: <code>--alwaysStrict --strictBindCallApply --strictFunctionTypes --target ES2024</code></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 6.3.2 version of <a href=\"https://github.com/datastructures-js/priority-queue/tree/v6.3.2\" target=\"_blank\">datastructures-js/priority-queue</a> and 4.2.3 version of <a href=\"https://github.com/datastructures-js/queue/tree/v4.2.3\" target=\"_blank\">datastructures-js/queue</a> and 1.0.4 version of <a href=\"https://github.com/datastructures-js/deque/tree/v1.0.4\" target=\"_blank\">datastructures-js/deque</a>.</p>"], "racket": ["Racket", "<p><a href=\"https://docs.racket-lang.org/guide/performance.html#%28tech._c%29\" target=\"_blank\">Racket CS</a> v8.15</p>\r\n\r\n<p>Using <code>#lang racket</code></p>\r\n\r\n<p>Required <code>data/gvector data/queue data/order data/heap</code> automatically for your convenience</p>"], "erlang": ["Erlang", "Erlang/OTP 26"], "elixir": ["Elixir", "Elixir 1.17 with Erlang/OTP 26"], "dart": ["Dart", "<p>Dart 3.2. You may use package <a href=\"https://pub.dev/packages/collection/versions/1.18.0\" target=\"_blank\">collection</a></p>\r\n\r\n<p>Your code will be run directly without compiling</p>"]}
['Array', 'Hash Table', 'Tree', 'Depth-First Search', 'Breadth-First Search', 'Design']