Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
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
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess 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
Build my plan
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

Your question is Permission System With Trees. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.