Company: Juspay_28june
Difficulty: medium
Locking the tree of space Problem Description You have a world map represented as an M-Ary tree. An example of such a tree is shown below, illustrating a hierarchy from 'World' down to specific regions like 'BLR'. For instance, in a complete 3-ary tree, if m = 3, N = 121 represents the number of nodes. You need to define three operations on this tree: lock(X, uid) unlock(X, uid) upgradeLock(X, uid) Where X is the name of a node in the tree (which would be unique) and uid is the user who is performing the operation. Here are the definitions for the 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 descendant of X . lock(B, anyUserId) should fail (returns false), where X is a descendant of B . Lock operation cannot be performed on a node which is already locked, i.e., lock(X, anyUserId) should fail (returns false). Unlock(X, u