← Meta Interview Insights

Meta·Data Scientist·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Coding round for a Data Scientist role at Meta, three Python problems all leaning on data structure fundamentals. Nothing too wild but the third question had some tricky edge cases I didn't fully anticipate in time.

Questions Asked (3)

Q1

Given an integer, rearrange only its odd digits to form the smallest possible integer, completely ignoring any even digits.

Algorithms & Data Structures
Author's notes

Filter, sort, rejoin.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First clarify the problem: extract all odd digits from the integer, sort them in ascending order, and concatenate to form the smallest possible integer. Then discuss edge cases such as no odd digits, leading zeros, and negative numbers, and analyze time and space complexity.

Pro tip: Mention that leading zeros are naturally avoided because sorting odd digits ascending places the smallest non-zero digit first, but if all odd digits are zero, the result is 0. Also, consider negative numbers: the smallest integer from odd digits of a negative number should be the negative of the largest possible integer formed by those digits (i.e., sort descending and negate).

1. Clarify the problem

Confirm that only odd digits are considered, even digits are ignored, and the goal is to form the smallest possible integer. Ask about negative numbers, leading zeros, and whether the input is a string or integer.

2. Extract odd digits

Iterate through the digits of the integer (or its string representation) and collect all odd digits into a list.

3. Sort and construct

Sort the list of odd digits in ascending order. If the number is negative, sort in descending order to get the smallest (most negative) integer. Concatenate the sorted digits to form the result.

4. Handle edge cases

If no odd digits exist, return 0 or indicate no valid integer. If the result has leading zeros (e.g., all odd digits are zero), the integer is 0. For negative numbers, apply the sign after sorting.

5. Analyze complexity

State that time complexity is O(d log d) where d is the number of odd digits (due to sorting), and space complexity is O(d) for storing the digits.

Key Points to Mention

  • Digit extraction: converting integer to string or using modulo arithmetic.
  • Sorting: ascending for positive numbers, descending for negative numbers to minimize the integer.
  • Leading zeros: they are naturally avoided because the smallest non-zero odd digit will be first after sorting, unless all odd digits are zero.
  • Edge cases: no odd digits, all odd digits are zero, negative numbers, and zero itself.
  • Time and space complexity: O(d log d) time and O(d) space, where d is the number of odd digits.
  • Alternative approaches: counting sort if digits are limited to 0-9, which gives O(d) time.

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

Q2

You have a dictionary mapping store names to lists of comments. Find the comment(s) that appear most frequently across all stores, but within each store, count duplicate comments only once.

Algorithms & Data Structures
Author's notes

The dedup-per-store part is what makes this non-trivial.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify that the goal is to find comments with the highest global frequency, where each store contributes at most one count per comment. Use a two-level aggregation: first deduplicate comments within each store, then count global occurrences across stores. Finally, identify the comment(s) with the maximum count, handling ties appropriately.

Pro tip: Mention that you would validate the input for edge cases like empty stores or empty comment lists, and discuss how to handle ties (e.g., return all tied comments). This shows attention to detail and production readiness.

1. Clarify requirements and edge cases

Confirm that duplicates within a store count once, and that we need the most frequent comment(s) globally. Ask about tie-breaking and empty inputs.

2. Deduplicate comments per store

For each store, convert its list of comments to a set to remove duplicates, ensuring each comment is counted at most once per store.

3. Aggregate global frequencies

Iterate over each store's unique comments and increment a global frequency dictionary for each comment.

4. Find the maximum frequency

Determine the highest count from the global frequency dictionary.

5. Return all comments with max frequency

Collect all comments whose global count equals the maximum and return them as the result.

Key Points to Mention

  • Deduplication within each store using a set to ensure each comment counts once per store.
  • Global frequency aggregation across stores using a hash map (dictionary).
  • Time complexity: O(N) where N is total number of comments across all stores, assuming set and dictionary operations are O(1) on average.
  • Space complexity: O(U + C) where U is number of unique comments per store and C is number of unique comments globally.
  • Handling ties: return all comments with the maximum frequency.
  • Edge cases: empty dictionary, stores with empty comment lists, all comments unique, all comments identical.

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

Q3

Given a list of objects each representing a class with a name, a total number of sessions, a start year, and an end year, find the maximum combined number of sessions that fall within any two consecutive calendar years.

Algorithms & Data Structures
Author's notes

This one tripped me up.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify how sessions are distributed across years (e.g., evenly or all in one year) and whether overlapping years count multiple times. Then, for each possible pair of consecutive years, compute the total sessions from all classes that overlap those years, and return the maximum. Use a sweep-line or interval-based approach to efficiently compute the sums.

Pro tip: Discuss the ambiguity of session distribution and propose a reasonable assumption (e.g., sessions are evenly distributed across the class's active years) to show you think about data realism. Also, mention that if sessions are concentrated in specific years, you'd need more granular data.

1. Clarify assumptions and constraints

Ask how sessions are distributed across years (evenly, all in start year, etc.) and whether a class active in both years counts its sessions once or twice. Confirm the definition of 'combined number of sessions'.

2. Define the computation for a year pair

For a given pair of consecutive years (y, y+1), sum the sessions of all classes whose active period overlaps with either year. If sessions are evenly distributed, compute the fraction of the class's total sessions that fall in those years.

3. Choose an efficient algorithm

Use a sweep-line over years or precompute prefix sums of sessions per year to evaluate all consecutive year pairs in O(n log n) or O(n + Y) time, where Y is the range of years.

4. Handle edge cases and validate

Consider classes with start year > end year (invalid), classes spanning only one year, and years with no classes. Test with small examples to ensure correctness.

5. Analyze complexity and discuss trade-offs

State the time and space complexity of your solution and discuss potential optimizations or alternative approaches (e.g., if sessions are not evenly distributed).

Key Points to Mention

  • Clarify session distribution assumption (even vs. concentrated) and its impact on the answer.
  • Define overlap: a class contributes to a year if its active period intersects that year.
  • Use a sweep-line or prefix-sum approach to efficiently compute sums for all consecutive year pairs.
  • Handle edge cases: classes with zero sessions, single-year classes, and years with no activity.
  • Discuss time and space complexity, aiming for O(n log n) or better.
  • Mention that if sessions are not evenly distributed, additional data or assumptions are needed.

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