Solve Data-Structure Problems in Python Interview Round
Company: Meta
Role: Data Scientist
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This question evaluates proficiency in data-structure manipulation and aggregation in Python, covering digit/string processing, frequency counting with group-level deduplication, and interval-based summation across records.
Smallest Integer From Odd Digits
Constraints
- n fits in a signed 32-bit integer.
- Only digits 1, 3, 5, 7, 9 are considered odd.
- Return -1 if the number has no odd digits.
- The sign of n does not affect the result.
Examples
Input: (12345,)
Expected Output: 135
Explanation: Odd digits 1,3,5 sorted ascending form 135.
Input: (2468,)
Expected Output: -1
Explanation: No odd digits, so -1.
Hints
- Iterate over the decimal digits of |n| and keep only the odd ones.
- Sorting the odd digits ascending yields the smallest possible arrangement.
- Handle the empty case (no odd digits) by returning -1.
Most Frequent Comments Across Stores
Constraints
- Comments are compared by exact string equality.
- Within a store, duplicate comments count as one.
- Ties are all returned, sorted ascending.
- Return [] for an empty input dictionary.
Examples
Input: ({'A': ['good', 'good', 'bad'], 'B': ['good', 'ok'], 'C': ['good', 'bad']},)
Expected Output: ['good']
Explanation: 'good' is in all 3 stores (its repeat in A counts once); 'bad' only 2; 'ok' only 1.
Input: ({'A': ['x', 'x', 'x'], 'B': ['y'], 'C': ['z']},)
Expected Output: ['x', 'y', 'z']
Explanation: After per-store dedup each comment appears in exactly 1 store, so all tie at count 1.
Hints
- Convert each store's comment list to a set to deduplicate within the store.
- Accumulate a global Counter over the deduped per-store comments.
- Find the maximum count, then return every comment achieving it, sorted.
Maximum Class Total Over Two Consecutive Years
Constraints
- Each class contributes its number_of_classes to every year in [start_year, end_year] inclusive.
- start_year <= end_year for every class.
- A two-consecutive-year window is (y, y+1); a lone busiest year (paired with an empty year) is also valid.
- Return 0 when the list is empty.
Examples
Input: ([['Math', 3, 2020, 2021], ['Science', 2, 2021, 2022]],)
Expected Output: 8
Explanation: Year totals 2020:3, 2021:5, 2022:2; best pair 2020+2021 = 8.
Input: ([['Solo', 5, 2020, 2020]],)
Expected Output: 5
Explanation: Only 2020 is active with total 5; no following year, so the answer is 5.
Hints
- Expand each class into the years it spans and accumulate per-year totals.
- Scan years in order; for each year y, the window value is total[y] + total[y+1].
- Initialize the answer with the busiest single year so a one-year span is covered.