Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Permission Deletion Logic

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Permission Deletion Logic. Start with the requirements on the right.

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.

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):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output