Answer Is-Prerequisite Queries Over a Permission Hierarchy

Last updated: November 29, 2026

Quick Overview

Permissions form a DAG where an edge [a, b] means holding permission a implies permission b. Given n permissions, the edges, and many queries [u, v], return for each query whether holding u implies v, directly or transitively.

Meta
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Permissions form a DAG where an edge [a, b] means holding permission a implies permission b. Given n permissions, the edges, and many queries [u, v], return for each query whether holding u implies v, directly or transitively.

A Meta technical screen problem in the style of the access control systems behind internal tools and Business Manager roles. The interviewer is looking for the trade-off between per-query BFS and precomputing reachability, and expects you to choose based on the query volume and graph size.

What the Interviewer Expects
  • Compare per-query search with precomputed transitive closure
  • Propagate reachability sets in reverse topological order
  • Use bitsets or Python ints to make closure cheap
  • State time and memory for both approaches
  • Answer queries in O(1) after preprocessing
Key Topics to Cover
transitive closure
topological order
bitset
reachability queries
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • What if n is one million and queries are rare?
  • How would you update the closure when a new edge is added?
  • How would you support an edge removal efficiently?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Input: n permissions 0..n-1, DAG edges [a, b], and queries [u, v].
  • Output: a list of booleans, True if v is reachable from u.
  • Clarify sizes: here n is up to a few hundred and...
High-Level Design

Two options:

  1. BFS per query: O(q (n + e)). Fine when queries are rare.
  2. Transitive closure: compute reach[u], the set of nodes reachable from u, once. Then each query is a bit test....

Submit Your Answer
Markdown supported