Software Engineer • Senior-Level
Software Engineer • Senior-Level
High QualityPrep Other Coding Questions Asked by Reddit
Continue with targeted prep from Reddit's coding question bank.
Interview Summary
I passed Reddit's Software Engineer technical phone screen, which featured a tree traversal problem based on filtering Reddit comments according to user preferences. The main challenge was that filtering a comment also required removing its entire reply subtree, even when descendants did not independently violate the user's preferences. The problem also included large-input constraints and deeply nested comment threads.
Interview Details
Coding Screen: Filter Reddit Comment Subtrees by User Preference
You are given a dictionary representing a collection of Reddit comments. Each comment contains the following fields:
id: A unique integer identifying the comment.parent_comment: The ID of its parent comment, orNoneif it is a root comment.body: The comment's text content, which is irrelevant to the filtering logic.cat: A boolean indicating whether the comment discusses cats.dog: A boolean indicating whether the comment discusses dogs.
The comments form a tree through their parent-child relationships. Your task is to identify which comments should be hidden based on the current user's preferences.
User Preference Modes
The system supports two modes:
CAT_PERSON: The user does not want to see dog-related comments.DOG_PERSON: The user does not want to see cat-related comments.
A comment should be excluded if it discusses an animal that the current user does not want to see. However, the filtering rule extends beyond the comment itself. If a comment is excluded, every descendant of that comment must also be excluded, regardless of the descendants' individual labels. This means a neutral comment may still need to be hidden if one of its ancestors violates the user's preferences.
**Function
Unlock Full Details
Create a free account to unlock this interview experience report.