Reddit interview question
Answer moderator removal permissions and seniority rankings from effective access timestamps
- Company:
- Type:
- Coding
- Difficulty:
- Medium
- Reported:
- October 19, 2026
Problem
A community platform keeps a moderator hierarchy. Every active moderator has an effective access timestamp, and that timestamp decides rank: an earlier timestamp means a higher rank, and a moderator may remove only moderators ranked below them.
The history arrives as a log of moderator actions that you replay in order and then query. The log is newline-separated text with comma-separated fields, but the prompt does not give the field order, so this write-up works on records that have already been split into fields (one method call per record); agree on the exact line format with the interviewer before writing the parser. The task grows in three parts.
Part 1: one moderator list.
add(user, timestamp):userbecomes an active moderator whose effective access timestamp istimestamp.remove(user):useris no longer an active moderator.get_mod_list(): the active moderators from highest to lowest rank.can_remove_mod(actor, target): whetheractormay removetarget, that is, both are active moderators andactorranks abovetarget.
Part 2: communities. Every community keeps its own independent moderator list, so every record and every query takes the community as an extra first argument.
Part 3: demote. A demote(user, timestamp) action reassigns the moderator's effective access timestamp to the value given with the action, which reorders the list.
The prompt leaves several cases open, and any consistent handling is accepted: an add for a moderator who is already active, a remove or demote naming someone who is not an active moderator, and two moderators with equal timestamps.
Example 1
Input: add("alice", 100), add("bob", 105), add("carol", 110), remove("bob"), add("dave", 130)
get_mod_list(), can_remove_mod("carol", "dave"), can_remove_mod("dave", "alice"), can_remove_mod("alice", "bob")
Output: ["alice", "carol", "dave"], True, False, False
bob is no longer a moderator, so alice cannot remove him; carol (110) outranks dave (130).
Example 2
Input: add("cats", "alice", 1), add("dogs", "bob", 2), add("cats", "carol", 3),
add("dogs", "alice", 4), add("cats", "erin", 5), demote("cats", "alice", 6)
get_mod_list("cats"), get_mod_list("dogs"), can_remove_mod("dogs", "alice", "bob"), can_remove_mod("cats", "erin", "alice")
Output: ["carol", "erin", "alice"], ["bob", "alice"], False, True
The demote gives alice timestamp 6 in cats, which moves her below erin there. In dogs she ranks below bob, and her rank in cats does not affect it.
Constraints
- Timestamps are comparable numbers; records are replayed in the order given.
- Communities are independent of each other.
Reported by candidates or drawn from publicly available sources, and rewritten in our own words. Pathwise Prep does not publish confidential assessment content. Report a concern