Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Validate Access Rights by Role
00:00
5 left

Validate Access Rights by Role

EasyPython

Problem

Write a function to validate user access rights based on predefined roles.

Implement validate_access(user_roles, role_permissions, requested_permission). user_roles is a list of role names, and role_permissions maps each role to a list of permission names. Return True if at least one assigned role grants the requested permission, otherwise return False. Treat permission and role names as case-sensitive. You may assume every role in user_roles exists in role_permissions.

Constraints

  • 1 <= len(user_roles) <= 10^4
  • Each role maps to a list of zero or more permission names
  • Role and permission names are non-empty, case-sensitive strings
  • Every role in user_roles exists in role_permissions

Function Signature

def validate_access(user_roles, role_permissions, requested_permission):
Interviewer

Your question is Validate Access Rights by Role. 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
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.