Company: Juspay_13july
Difficulty: medium
Locking the tree of space Problem Description You are tasked with implementing a system to manage locks on nodes within an M-Ary tree, which represents a world map. The tree nodes are identified by unique names (strings), and operations are performed by users identified by unique integer IDs. You need to define three operations: lock(X, uid) unlock(X, uid) upgradeLock(X, uid) Where X is the name of a node in the tree, and uid is the user ID performing the operation. Definitions for Operations: Lock(X, uid) Lock takes an exclusive access on the subtree rooted at X . It is formally defined like this: 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 . Lock operation cannot be performed on a node which is already locked, i.e., lock(X, anyUserId) should fail (returns false). In summary, a node X can be locked by a user uid only if: Node X is not curren