← Questions

Lock, unlock and upgrade nodes in a tree

0
AmazonCodingLast asked Aug 2025

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.

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding