Design a LockTree over n nodes numbered 0 to n-1, built from a parent array in which the single root has parent -1 (node 0 in the example below). lock(node, user) returns true and locks the node only if the node is unlocked and none of its ancestors and none of its descendants is locked, and unlock(node, user) returns true and frees the node only if that same user locked it; otherwise a call returns false and changes nothing. The input is an operation list like a LeetCode design problem: run(ops, args) returns null for the constructor "LockTree" and a boolean for every later call, so with parent [-1,0,0,1,1,2] the calls lock(1,7), lock(3,8), unlock(1,8) return true, false (ancestor 1 is locked), false (wrong user). There are up to 100,000 nodes and calls, user ids are positive integers, and the tree height stays under 1,000.
The run(ops, args) helper is already written: it builds the tree from the first operation and calls the methods for the rest. Fill in the class.