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
Role Privilege Inheritance
00:00
5 left

Role Privilege Inheritance

MediumPython

Problem

In Snowflake role-based access control, a role inherits all privileges assigned to its ancestor roles. Given each role's directly assigned privileges and direct inheritance grants, compute the complete privilege set for every role.

A grant [parent, child] means the child role inherits the parent's privileges. Return one sorted list of unique privilege names per role, including privileges assigned directly to that role and inherited through any number of ancestors.

Formal Specification

Implement calculate_privileges(privileges, grants).

  • privileges is a list of lists of strings, where privileges[i] contains privileges directly assigned to role i.
  • grants is a list of two-element integer lists. Each [parent, child] represents a direct inheritance relationship.
  • Return a list of lists of strings. The result at index i must contain every privilege role i can receive, sorted lexicographically.

The inheritance graph is guaranteed to be a directed acyclic graph, and each role index is valid.

Constraints

  • 1 <= len(privileges) <= 10^4
  • 0 <= len(grants) <= 5 * 10^4
  • Each privilege list contains at most 10^3 strings
  • Privilege names contain printable non-whitespace characters
  • The inheritance graph is acyclic
  • Duplicate direct assignments and duplicate grants are allowed

Function Signature

def calculate_privileges(privileges, grants):
Interviewer

Your question is Role Privilege Inheritance. 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.