Grant / Revoke / Check Access on Hierarchy

Asked at Pinterest · Coding Questions · Difficulty: Medium · Last asked Apr 21, 2026

Design an access-control class on a static hierarchy (world -> country -> city). `grant_access(entity, group)` and `revoke_access(entity, group)` must be O(1); `check_access(entity, group)` is O(depth) by walking up the hierarchy and OR-ing access bits along the path. The trick is to look up the tree, not down, at check time.

Loading the problem…