← Reddit Interview Insights

Reddit·Data Scientist·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

SQL round for a Data Scientist role at Reddit. Two questions, both centered on user/post data with some real edge cases baked in. Not the hardest SQL I've seen but the details trip you up if you're not careful.

Questions Asked (2)

Q1

Given a users table and a posts table, write a SQL query to classify each user as 'in the US' or not. A user counts as US-based if their home country is US, or if at least 50% of their posts in the last 30 days came from a US IP. Return user_id, a binary flag, and the share of US posts over the last 30 days (null if they have no recent posts).

Product Analytics & MetricsData Modeling
Author's notes

This one has more moving parts than it looks.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Break the problem into two parts: first, compute the share of US posts per user in the last 30 days using a conditional aggregation on the posts table; second, join that to the users table and apply the classification logic (home country = 'US' OR share >= 0.5). Use a LEFT JOIN to preserve users with no recent posts, and handle nulls appropriately.

Pro tip: Clarify the definition of 'US IP' (e.g., IP country code) and the time window (last 30 days relative to current date) before writing the query; also mention that the binary flag should be 1 if either condition holds, even if the share is null.

1. Understand the schema and definitions

Identify the relevant columns: users table has user_id and home_country; posts table has user_id, post_timestamp, and ip_country (or similar). Clarify that 'US IP' means ip_country = 'US' and 'last 30 days' means post_timestamp >= CURRENT_DATE - INTERVAL '30 days'.

2. Compute US post share per user

Aggregate posts from the last 30 days per user: count total posts and count posts where ip_country = 'US'. Compute the share as us_posts / total_posts. Use a subquery or CTE.

3. Join with users and classify

LEFT JOIN the aggregated post stats to the users table on user_id. Then compute the binary flag: 1 if home_country = 'US' OR us_share >= 0.5, else 0. Ensure that users with no recent posts get a null share and are classified solely based on home_country.

4. Handle edge cases and output

Use COALESCE or CASE to handle nulls in the share. Return user_id, the binary flag, and the share (null if no recent posts). Optionally round the share for readability.

Key Points to Mention

  • Use of conditional aggregation (SUM(CASE WHEN ... THEN 1 ELSE 0 END)) to count US posts.
  • LEFT JOIN to include users with no posts in the last 30 days.
  • Handling of NULL share for users with no recent posts.
  • Definition of 'US-based' as an OR condition: home country US or >=50% US posts.
  • Time window filtering: post_timestamp >= CURRENT_DATE - INTERVAL '30 days'.
  • Potential data quality issues: missing IP country, multiple posts per user, timezone considerations.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q2

Write a SQL query to find the top 10 most active forums over the last 30 days, ranked first by total post count and then by distinct poster count as a tiebreaker. Return forum_id, forum_name, post count, and active user count.

Product Analytics & MetricsData Modeling
Author's notes

Straightforward ranking question.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the schema and definitions (e.g., what constitutes a post, how to handle deleted posts, and time zone for the 30-day window). Then write a query that filters posts from the last 30 days, joins to forums, aggregates by forum to compute total posts and distinct posters, and finally orders by post count descending, then distinct posters descending, limiting to 10.

Pro tip: Mention that you would exclude deleted or removed posts and consider using a subquery to filter posts first for performance, especially if the posts table is large. Also, clarify whether 'active user' means distinct posters or distinct commenters, as this can change the query.

1. Clarify requirements and schema

Ask about the table structures (e.g., posts, forums, users), definitions of 'post' and 'active user', and how to handle deleted posts or time zones. Confirm the exact output columns and ordering.

2. Filter posts for the last 30 days

Use a WHERE clause on the post creation timestamp to select only posts from the last 30 days relative to the current date. Consider using a subquery to reduce the dataset early.

3. Aggregate by forum

Join the filtered posts to the forums table, then GROUP BY forum_id and forum_name. Compute COUNT(*) for total posts and COUNT(DISTINCT user_id) for distinct posters.

4. Rank and limit results

Order the results by total post count descending, then by distinct poster count descending. Use LIMIT 10 to get the top 10 forums.

5. Validate and optimize

Check for edge cases (e.g., forums with no posts in the period) and consider indexing on post timestamp and forum_id for performance. Explain the query and results.

Key Points to Mention

  • Definition of 'active user' as distinct posters (or clarify if it includes commenters/voters).
  • Handling of deleted or removed posts (exclude them).
  • Time zone considerations for the 30-day window (use UTC or specify).
  • Use of COUNT(DISTINCT user_id) for distinct poster count.
  • Ordering by post count DESC, then distinct poster count DESC.
  • Performance optimization: filter early, use indexes, avoid unnecessary joins.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.