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
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
Get started
Permission Deletion Logic
00:00
5 left

Permission Deletion Logic

MediumPython

Problem

The Reddit Admin Portal stores administrator creation records. Implement can_delete_admin to determine whether deleter may delete target.

An administrator may delete another administrator only when both conditions hold:

  1. deleter is a strict ancestor of target in the creation hierarchy, meaning deleter directly or indirectly created target.
  2. deleter was created earlier than target.

The records may appear in any order. Every referenced administrator exists, each non-root administrator has exactly one creator, and the hierarchy contains no cycles.

Formal Specification

Input admins is a list of dictionaries. Each dictionary has:

  • id: a unique string identifying an administrator
  • creator: the creator's ID, or None for a root administrator
  • created_at: a unique integer timestamp, where a smaller value means earlier creation

deleter and target are administrator ID strings. Return a boolean. Return False when they are the same administrator or when the hierarchy and timestamp requirements are not both satisfied.

Constraints

  • 1 <= len(admins) <= 10^5
  • IDs are unique non-empty strings
  • Timestamps are unique integers in [-10^9, 10^9]
  • The hierarchy is a valid forest with no cycles
  • Every creator ID referenced by a record appears in admins

Function Signature

def can_delete_admin(admins, deleter, target):
Interviewer

Your question is Permission Deletion Logic. 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.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.