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.
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:
deleter is a strict ancestor of target in the creation hierarchy, meaning deleter directly or indirectly created target.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.
Input admins is a list of dictionaries. Each dictionary has:
id: a unique string identifying an administratorcreator: the creator's ID, or None for a root administratorcreated_at: a unique integer timestamp, where a smaller value means earlier creationdeleter 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.
def can_delete_admin(admins, deleter, target):