Reddit logo

Reddit Hard Interview Questions

7 hard-level practice questions for Reddit technical interviews

Reddit software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.

Software Engineer Backend Engineer Frontend Engineer Full Stack Engineer Mobile Engineer Data Engineer Data Scientist ML Engineer DevOps Engineer DevOps Engineer Product Manager SRE Security Engineer Engineering Manager Data Analyst UX/UI Designer QA Engineer
5
Coding
1
System Design
coding Hard Verified Question #1

1. Ping-Pong Match Scorer


Category: String coding problem
You are building a scoring system for competitive ping-pong matches. Points are awarded one at a time to a player, and the score must be tracked...
Input: String
Output: Computed result
Want to practise this one?
Create a free account to open the full question and practise Reddit questions with AI.
Sign up free
coding Hard Verified Question #2

2. Admin Permission System


Category: Trie-based coding problem
You are designing a system that tracks administrator privileges for an online platform using a time-ordered log of administration actions. Each log...
Input: List
Output: Computed result
coding Hard Verified Question #3

3. Expense Ledger


Category: Graph coding problem
A company's expense tracking database was lost. Fortunately, a complete historical log of all financial transactions was retained. Your task is to...
Input: Graph (nodes and edges)
Output: Computed result
coding Hard Verified Question #4

4. Document Context Merger


Category: Trie-based coding problem
A document review application maintains a history of entries where each entry is identified by a unique, strictly increasing integer id and...
Input: List
Output: Array
coding Hard Verified Question #5

5. Org Chart Navigator


Category: Tree coding problem
A company's reporting structure is described as a list relationships, where each element is a list of strings. The first string represents a...
Input: Array of strings
Output: Array
system design Hard Verified Question #6

6. Top 5 Reddit System Design Questions


Category: Trie-based system design problem

System Design Questions - Reddit These are the most commonly asked system design questions from Reddit interviews.

Input: Number(s)
Output: Computed result
coding Hard tree #1

1. [Tree] — Select visible Reddit comments after nested thread collapses


Background
Reddit comment threads contain nested replies, and collapsing a comment hides its descendants without hiding the comment itself. Consider a comment-view component that must preserve nested collapse states and efficiently locate a comment by its position among currently visible comments.
Problem statement
You are given a static forest of n comments numbered 0 through n - 1. The array parent specifies each comment's parent; parent[i] = -1 means comment i is a top-level comment. Top-level comments and each comment's immediate children are ordered by increasing comment ID. The complete display order is depth-first preorder: display a comment, then recursively display its children in order.
Initially, every comment is expanded. Process the following operations in order:
  • ("collapse", id): mark the comment collapsed. All of its strict descendants become hidden. The comment itself remains visible unless an ancestor is collapsed.

  • ("expand", id): clear that comment's collapsed state. Its descendants become visible only if they have no other collapsed ancestor.

  • ("select", k): return the ID of the k-th visible comment, using a 1-based position in display order. Return -1 if fewer than k comments are visible.


Collapsing an already collapsed comment or expanding an already expanded comment is a no-op. Operations may target hidden comments, and their individual collapse states must still be updated. Expanding an ancestor must not reset the collapse states of its descendants. Collapsing a leaf changes its state but hides nothing.
Return one result for each select operation. Your implementation must use O(n + q log n) time and O(n) auxiliary space, excluding the input and returned results, where q is the number of operations.
Function or class signature
  • visible_comments(parent: list[int], operations: list[tuple[str, int]]) -> list[int]


Example 1:
Input:
{
  "parent": [-1, 0, 0, 1, 1, 2, -1],
  "operations": [["select", 4], ["collapse", 1], ["select", 4], ["collapse", 0], ["select", 2], ["expand", 1], ["select", 3], ["expand", 0], ["select", 4]]
}

Output:
[4, 5, 6, -1, 4]

Explanation: Initially the display order is [0, 1, 3, 4, 2, 5, 6]. Collapsing 1 leaves [0, 1, 2, 5, 6]. Collapsing 0 leaves [0, 6]. Expanding the hidden comment 1 does not expose anything while 0 remains collapsed, so position 3 does not exist. Expanding 0 then restores the complete display order because 1 is already expanded.
Example 2:
Input:
{
  "parent": [-1, 0, 1, 1],
  "operations": [["collapse", 1], ["collapse", 0], ["expand", 0], ["select", 3], ["expand", 1], ["select", 3], ["collapse", 2], ["select", 4]]
}

Output:
[-1, 2, 3]

Explanation: After collapsing 1, collapsing 0, and expanding 0, only [0, 1] are visible: comment 1 retains its collapsed state. Expanding 1 restores [0, 1, 2, 3], whose third comment is 2. Collapsing leaf 2 changes no visibility, so the fourth comment remains 3.
Constraints:
  • 1 <= n <= 200000.

  • 0 <= q <= 200000.

  • parent[i] is -1 or an integer in [0, n - 1]; the array describes a valid acyclic forest.

  • Operation names are exactly collapse, expand, or select.

  • For collapse and expand, 0 <= id < n; for select, 1 <= k <= 200000.

  • The forest can contain a chain of length n; traversal must not depend on a language recursion limit proportional to n.


Follow-up:
How would you support inserting new replies while preserving existing sibling order, with each insertion, collapse, expansion, and selection taking amortized O(log n) time? Explain how you would replace the static preorder array and represent subtree boundaries.
Want to practise this one?
Create a free account to open the full question and practise Reddit questions with AI.
Sign up free

Start practicing Reddit questions

Sign up for free to access walkthroughs, AI-generated questions, and more.

Get Started Free