NeetCode #453LC-1993MediumTrees
← Back to All Problems

#453 · #1993 · Operations on Tree(树上的操作)

📌 Problem Statement & Constraints

Design a locking tree with n nodes numbered 0..n-1 and a parent array (parent[i] is the parent of i, -1 for the root). Implement lock(num, user), unlock(num, user) and upgrade(num, user). upgrade succeeds only when the node is unlocked, no ancestor is locked, and at least one descendant is locked; it then unlocks all locked descendants and locks the node. Constraints: 1 <= n <= 2000; at most 2000 calls.
🔒

Sign In to Unlock Full Solutions for All 973 Problems

Sign in to access step-by-step logic, benchmark Python3 code, complexity breakdown, and offline export!