CodingMachine Learning Engineer, Software EngineerReported May, 2026
Create a Reddit-like moderator hierarchy by processing a newline-separated audit log.
This interview prompt is commonly divided into three stages:
The governing permission rule is:
For the first stage, every record contains four comma-delimited values:
target, action, actor, timestamp
target: the moderator affected by the eventaction: add or remove for Parts 1 and 2; Part 3 also allows demoteactor: the moderator responsible for the eventtimestamp: an integer time value that advances through the logYou may rely on the following:
SYSTEM can act as the user that establishes the initial moderator, although it does not appear in the returned list unless it is itself added.Every stage requires the same three capabilities:
can_remove_mod(...)get_mod_list(...)Build a class that manages one moderator roster:
class ModList:
def __init__(self, logs: str):
pass
def can_remove_mod(self, actor: str, target: str) -> bool:
pass
def get_mod_list(self) -> list[str]:
pass
add event makes target an active moderator beginning at timestamp.remove event makes target inactive.can_remove_mod(actor, target) produces True exactly when:
actor != targetactor has an effective access timestamp earlier than targetget_mod_list() must return active moderators in descending rank order, from first to last.logs = """
nora,add,SYSTEM,11
owen,add,nora,12
priya,add,nora,13
quinn,add,owen,14
priya,remove,nora,15
""".strip()
mod_list = ModList(logs)
mod_list.can_remove_mod("nora", "owen") # True
mod_list.can_remove_mod("owen", "nora") # False
mod_list.can_remove_mod("owen", "quinn") # True
mod_list.get_mod_list() # ["nora", "owen", "quinn"]
nora joined before owen, and owen joined before quinn; priya was removed, so she is absent from the final ordering.
Expand the design so it handles separate moderator rosters for multiple communities. Records now use this layout:
community, target, action, actor, timestamp
Implement:
class CommunityModList:
def __init__(self, logs: str):
pass
def can_remove_mod(self, community: str, actor: str, target: str) -> bool:
pass
def get_mod_list(self, community: str) -> list[str]:
pass
can_remove_mod evaluates permissions only within the supplied community.logs = """
gardening,nora,add,SYSTEM,21
gardening,owen,add,nora,22
gardening,priya,add,nora,23
photography,riley,add,SYSTEM,24
photography,owen,add,riley,25
gardening,priya,remove,nora,26
""".strip()
mod_list = CommunityModList(logs)
mod_list.get_mod_list("gardening") # ["nora", "owen"]
mod_list.get_mod_list("photography") # ["riley", "owen"]
mod_list.can_remove_mod("gardening", "nora", "owen") # True
mod_list.can_remove_mod("photography", "owen", "riley") # False
In gardening, nora predates owen while priya was removed. In photography, riley has the earlier access time, so owen cannot remove her.
Enhance the multi-community design with a third possible event:
community, target, demote, actor, timestamp
A demotion leaves the target active but replaces their effective access timestamp with the demotion time. Put differently, the target moves lower in that community's moderator order.
Implement the same three methods:
class ReorderableCommunityModList:
def __init__(self, logs: str):
pass
def can_remove_mod(self, community: str, actor: str, target: str) -> bool:
pass
def get_mod_list(self, community: str) -> list[str]:
pass
logs = """
gardening,nora,add,SYSTEM,31
gardening,owen,add,nora,32
gardening,priya,add,nora,33
gardening,owen,demote,nora,34
""".strip()
mod_list = ReorderableCommunityModList(logs)
mod_list.get_mod_list("gardening") # ["nora", "priya", "owen"]
mod_list.can_remove_mod("gardening", "priya", "owen") # True
mod_list.can_remove_mod("gardening", "owen", "priya") # False
After owen is demoted, his effective timestamp becomes 34, placing him after priya, whose timestamp remains 33.
get_mod_list() run in O(m) without performing a new sort on every call?