Lock, unlock and upgrade nodes in a tree

0
Remix

A tree is given by a parent array. Implement lock(node, user), unlock(node, user) and upgrade(node, user): a node can be locked by a user if it is unlocked; unlocked only by the user who locked it; and upgraded when it is unlocked, none of its ancestors is locked and at least one descendant is locked, which locks it and unlocks all its descendants. The interviewer gave the problem vaguely, so clarify the rules first.

AmazonTechnical phone screenLast asked Aug 2025
No answer yet. Write the first one; the best answer gets endorsed.