Katkat

Find user who can access every camera

VerkadaSoftware Engineer · Onsite

Last updated

This problem tests your ability to model hierarchical access control systems as a directed graph and determine reachability using graph traversal techniques like BFS or DFS.

Problem Description

In a security system, users can be assigned permissions either directly to specific cameras or by being added to groups. Groups can contain other groups (nested hierarchies) and individual cameras. A user has access to a camera if they are in a group that has direct access to the camera, or if they are in a group that contains another group with access to that camera.

Given a list of users, their group memberships, group-to-group nesting, and group-to-camera access permissions, identify all users who have access to every single camera in the system.

Function Signature

def find_universal_users(users, group_memberships, group_hierarchy, camera_permissions, total_camera_count):

  • users: List of strings (user IDs).
  • group_memberships: List of (user_id, group_id) tuples.
  • group_hierarchy: List of (parent_group_id, child_group_id) tuples.
  • camera_permissions: List of (group_id, camera_id) tuples.
  • total_camera_count: Integer representing the total number of unique cameras in the system.

Examples

Input: users = ['A', 'B'] group_memberships = [('A', 'G1'), ('B', 'G2')] group_hierarchy = [('G1', 'G2')] camera_permissions = [('G2', 'C1'), ('G1', 'C2')] total_camera_count = 2

Output: ['A'] Explanation: User 'A' is in 'G1'. 'G1' has access to 'C2' and contains 'G2', which has access to 'C1'. Thus 'A' accesses both. 'B' only accesses 'C1'.

Constraints

  • 1 <= total_camera_count <= 1000
  • 1 <= number of users, groups, and cameras <= 5000
  • Handle cycles in group_hierarchy (if a cycle exists, permissions propagate through all nodes in the cycle).
  • Return user IDs in any order.

Hints

Hint 1

Model the groups as nodes in a graph where edges represent group membership and access permissions.

Hint 2

For each user, find all unique cameras they can access by traversing the hierarchy starting from their assigned groups.

Hint 3

A user has universal access if the count of unique cameras reachable from their starting groups equals the total_camera_count.

Follow-up questions

  • How would your solution change if permissions were explicitly 'denied' in certain groups?
  • If the number of cameras grows to millions, how can we optimize the storage of access sets per user?
  • How would you detect cycles in the group hierarchy to prevent infinite loops during traversal?