← LinkedIn Interview Insights

LinkedIn·Data Scientist·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
May 2026

Summary

LinkedIn Data Scientist SQL round, two related questions that build on each other. Pretty clean problem setup but the histogram part tripped me up more than I expected.

Questions Asked (2)

Q1

Given a table of article views and a table of articles with their types, write a query to find, for each user, how many distinct article types they viewed on a specific date.

Product Analytics & MetricsData Modeling
Author's notes

Straightforward join and count distinct, nothing fancy.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the schema and the exact definition of 'distinct article types viewed'—likely counting unique article types per user per day. Then, write a SQL query that joins the views table with the articles table on article_id, filters for the specific date, groups by user_id, and counts distinct article types.

Pro tip: Mention that you would first check for data quality issues like duplicate views or missing article types, and consider using a subquery or CTE to filter the date before joining to improve performance.

1. Clarify requirements and schema

Ask about the table structures, column names, and whether 'specific date' is a parameter or hardcoded. Confirm that 'distinct article types' means unique type values per user.

2. Filter views for the target date

Use a WHERE clause to restrict the views table to the specific date, reducing the dataset before joining.

3. Join views with articles

Join the filtered views with the articles table on article_id to associate each view with its article type.

4. Group by user and count distinct types

Group the joined result by user_id and use COUNT(DISTINCT article_type) to get the number of distinct types viewed per user.

5. Handle edge cases and validate

Consider users with no views on that date (may need LEFT JOIN or separate handling) and validate results with a small sample.

Key Points to Mention

  • Use of COUNT(DISTINCT column) to count unique article types.
  • Filtering the date before joining to optimize performance.
  • Joining views and articles tables on article_id.
  • Grouping by user_id to get per-user counts.
  • Handling potential NULLs or missing article types.
  • Considering timezone or date format issues if the date is stored as timestamp.

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

Q2

Using the result from the previous query, build a histogram showing how many users viewed exactly 1 article type, exactly 2 types, and so on, for that same date.

Product Analytics & MetricsData Modeling
Author's notes

This is where I slowed down.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify that the previous query returns a per-user count of distinct article types viewed on the given date. Then, wrap that query in a subquery or CTE and apply a GROUP BY on the distinct type count to get the histogram of users by number of article types viewed.

Pro tip: Mention that you would validate the histogram by checking that the sum of user counts equals the total number of active users on that date, and consider whether zero-type users should be included based on the business question.

1. Clarify the base query

Ensure the previous query correctly computes, for each user, the number of distinct article types viewed on the specified date. Confirm the date filter and that the query returns one row per user with a count column.

2. Wrap as subquery or CTE

Use the previous query as a subquery or CTE so you can aggregate over its results. This keeps the logic modular and avoids repeating complex joins or filters.

3. Group by distinct type count

In the outer query, group by the count of distinct article types and count the number of users in each group. This produces the histogram: number of users who viewed exactly 1 type, exactly 2 types, etc.

4. Order and format results

Order the results by the number of article types (ascending) to make the histogram easy to read. Optionally, include a row for users with 0 types if relevant, and ensure the output columns are clearly labeled.

5. Validate and interpret

Check that the sum of users across all buckets equals the total number of users who viewed at least one article type on that date. Discuss any insights, such as the most common number of article types viewed.

Key Points to Mention

  • Use of COUNT(DISTINCT article_type) to compute the number of distinct types per user.
  • The need to filter by the specific date in the base query.
  • Using a subquery or CTE to separate the per-user aggregation from the histogram aggregation.
  • Grouping by the distinct type count and counting users to build the histogram.
  • Handling edge cases: users with zero views, and ensuring the date filter is applied correctly.
  • Validating the histogram by checking that the total user count matches the number of active users on that date.

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