Company: Juspay_24sep
Difficulty: medium
Locking the tree of space Problem Description You have a world map represented as an M-Ary tree. An example tree structure is shown below: World (root) Asia India KA BLR MP TN China Africa For a complete 3-ary tree, m = 3 , and N = 121 represents the number of nodes. You need to define three operations on this tree. For each operation, X is the name of a node in the tree (which is unique) and uid is the user ID who is performing the operation. 1. Lock(X, uid) Lock takes an exclusive access on the subtree rooted at X . It is formally defined as follows: Once lock(X, uid) succeeds, then: lock(A, anyUserid) should fail (returns false ), where A is a descendent of X . lock(B, anyUserid) should fail (returns false ), where X is a descendent of B (i.e., B is an ancestor of X ). A Lock operation cannot be performed on a node which is already locked, i.e., lock(X, anyUserid) should fail (returns false ). 2. Unlock(X, uid) Unlock reverts what was done by the Lock operation. It can only be calle