← LinkedIn Interview Insights

LinkedIn·Data Scientist·Technical Phone Screen·Intermediate

Intermediate
Jul 2026

Summary

SQL-heavy technical screen for a Data Scientist role at LinkedIn. Three progressively harder questions all on the same table, starting with a basic group-by and ending with window functions and percentage calculations. Felt manageable but the last part tripped me up a bit.

Questions Asked (3)

Q1

Given a table of countries with their continent and population, write a query to return the most populous country in each continent.

Data ModelingProduct Analytics & Metrics
Author's notes

Pretty standard warm-up.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the table schema and whether ties need handling. Then use a window function like ROW_NUMBER() partitioned by continent and ordered by population descending to select the top country per continent. Finally, filter to only the top-ranked rows.

Pro tip: Mention that window functions are more efficient and readable than self-joins or correlated subqueries, and that you'd handle ties by either using RANK() or specifying a tiebreaker like country name.

1. Clarify the schema and requirements

Confirm the table name, columns (country, continent, population), and whether ties should be broken or all tied countries returned.

2. Choose the right SQL technique

Decide between window functions (e.g., ROW_NUMBER, RANK) or alternative methods like GROUP BY with a join, considering performance and readability.

3. Write the query with a window function

Use ROW_NUMBER() OVER (PARTITION BY continent ORDER BY population DESC) to rank countries within each continent, then filter for rank = 1.

4. Handle edge cases and validate

Consider ties (use RANK() if needed), null populations, and verify the query returns one row per continent.

Key Points to Mention

  • Window functions (ROW_NUMBER, RANK, DENSE_RANK) for partitioning by continent
  • Ordering by population descending to get the most populous
  • Filtering to the top rank per partition
  • Handling ties: ROW_NUMBER vs RANK vs DENSE_RANK
  • Performance considerations: window functions vs self-joins or correlated subqueries
  • Potential need for a tiebreaker (e.g., alphabetical by country) for deterministic results

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

Q2

Follow-up: modify your solution to return the top 2 most populous countries per continent, including a rank column where 1 means the largest.

Data ModelingAlgorithms & Data Structures
Author's notes

Basically the same query, just changed the filter from rank = 1 to rank <= 2.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a window function like ROW_NUMBER() partitioned by continent and ordered by population descending, then filter to ranks 1 and 2. This efficiently handles ties and returns the top 2 per group in a single query.

Pro tip: Mention that if ties are possible, you might need to decide between ROW_NUMBER, RANK, or DENSE_RANK based on business requirements, and clarify that ROW_NUMBER arbitrarily breaks ties while RANK assigns the same rank to ties.

1. Clarify requirements

Confirm the definition of 'top 2' (e.g., handle ties) and the desired output columns (continent, country, population, rank).

2. Choose ranking function

Select ROW_NUMBER() for unique ranks, or RANK()/DENSE_RANK() if ties should share ranks, and explain the trade-offs.

3. Write the query

Use a window function partitioned by continent, ordered by population descending, and filter for rank <= 2.

4. Validate and optimize

Check for ties, ensure correct ordering, and consider indexing or partitioning strategies for large datasets.

Key Points to Mention

  • Window functions (ROW_NUMBER, RANK, DENSE_RANK) for per-group ranking
  • PARTITION BY continent ORDER BY population DESC
  • Filtering with a subquery or QUALIFY clause (if supported)
  • Handling ties: ROW_NUMBER vs RANK vs DENSE_RANK
  • Performance considerations: indexing, partitioning, and avoiding full table scans
  • Output format: including a rank column and ensuring correct ordering

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

Q3

For those top 2 countries per continent, compute each country's share of the continent's total population, rounded to 2 decimal places.

Data ModelingProduct Analytics & MetricsTechnical Trade-offs
Author's notes

This one took me longer than I'd like to admit.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the definition of 'top 2 countries per continent' (e.g., by population) and the data source. Then write a SQL query that ranks countries within each continent by population, filters to top 2, and computes each country's population as a percentage of the continent's total population, rounding to 2 decimal places.

Pro tip: Always confirm whether 'top 2' means top 2 by population or another metric, and whether the continent total includes all countries or only the top 2. This ambiguity can change the result significantly.

1. Clarify requirements

Ask clarifying questions: What defines 'top 2'? Is it by population? Should the continent total include all countries or only the top 2? What is the data source and schema?

2. Rank countries within continents

Use a window function like ROW_NUMBER() or RANK() partitioned by continent and ordered by population descending to identify the top 2 countries per continent.

3. Compute continent totals

Calculate the total population for each continent, either as a separate aggregation or using a window function SUM() OVER (PARTITION BY continent).

4. Calculate and round shares

For each top 2 country, divide its population by the continent total, multiply by 100, and round to 2 decimal places using ROUND().

5. Validate and present results

Check that the sum of shares for each continent is ≤ 100% (or exactly 100% if only top 2 are considered) and format the output clearly.

Key Points to Mention

  • Use of window functions (ROW_NUMBER, RANK, SUM OVER) for ranking and totals
  • Handling ties in population (e.g., using RANK vs ROW_NUMBER)
  • Definition of continent total (all countries vs top 2 only)
  • Rounding and potential precision issues (e.g., using ROUND or CAST)
  • Data quality checks (e.g., missing values, duplicates)
  • Performance considerations for large datasets (e.g., indexing, partitioning)

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