Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Start free
Permission System With Trees
00:00
5 left

Permission System With Trees

HardPython

Problem

How would you design a permission system using a tree data structure?

Implement permission_queries(parent, permissions, operations). parent maps each node to its parent, with the root mapped to None. permissions[node][principal][action] is either "allow" or "deny". Operations are ['grant', node, principal, action], ['revoke', node, principal, action], or ['check', node, principal, action]. A permission is inherited from ancestors, and the closest explicit rule wins. Return booleans for check operations in order.

Constraints: the structure is a valid rooted tree, node depth is at most 5,000, and there are at most 5,000 operations. Actions and principals are non-empty strings.

Constraints

  • parent describes a valid rooted tree with 1 to 5,000 nodes
  • The root is the only node whose parent is None
  • Every operation references an existing node
  • There are 1 to 5,000 operations
  • Each operation is a list of four strings
  • Each permission value is either "allow" or "deny"
  • A missing rule defaults to deny

Function Signature

def permission_queries(parent, permissions, operations):
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements are in the Question tab.

Sign up free to run or submit. Log in
Code
Sign up free to run your code. Your draft is saved.Run with a free accountLog inLn 2
Run your code to see test output here.