PracHub
QuestionsLearningGuidesInterview Prep

Quick Overview

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.

  • medium
  • Meta
  • Coding & Algorithms
  • Data Scientist

Solve Data-Structure Problems in Python Interview Round

Company: Meta

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

##### Scenario Interview coding round focusing on simple data-structure problems in Python. ##### Question Given an integer, rearrange its digits (considering only odd digits) to create the smallest possible integer; ignore even digits entirely. 2) You are given a dictionary {store_name: [comments]}. Return the comments that appear most frequently across all stores; within a single store, count completely identical comments only once. 3) Given a list of class objects with attributes name, number_of_classes, start_year, end_year, compute the maximum total number_of_classes that occurs in any two consecutive calendar years. ##### Hints Think about filtering digits, using Counter / sets for deduplication per store, and mapping yearly ranges to counts.

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

Given an integer `n`, keep only its odd digits (1, 3, 5, 7, 9), discard every even digit, and rearrange the remaining odd digits to form the smallest possible non-negative integer. The sign of `n` is irrelevant (treat the input by its absolute value). If `n` has no odd digits, return -1. Examples: - `12345` -> odd digits are 1, 3, 5 -> smallest arrangement `135`. - `2468` -> no odd digits -> `-1`. - `975312468` -> odd digits 9,7,5,3,1 -> `13579`. Return the resulting integer (or -1 when no odd digits exist).

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

  1. Iterate over the decimal digits of |n| and keep only the odd ones.
  2. Sorting the odd digits ascending yields the smallest possible arrangement.
  3. Handle the empty case (no odd digits) by returning -1.

Most Frequent Comments Across Stores

You are given a dictionary mapping each store name to a list of its comments. Find the comment(s) that appear in the most stores. Within a single store, identical comments are counted only once (deduplicate per store before counting), so a comment can contribute at most 1 to its cross-store count even if a store repeats it. Return a list of all comments tied for the maximum cross-store count, sorted in ascending (lexicographic) order. If the input is empty, return an empty list. Example: `{'A': ['good','good','bad'], 'B': ['good','ok'], 'C': ['good','bad']}` -> 'good' appears in all 3 stores, 'bad' in 2 stores, 'ok' in 1 -> return `['good']`.

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

  1. Convert each store's comment list to a set to deduplicate within the store.
  2. Accumulate a global Counter over the deduped per-store comments.
  3. Find the maximum count, then return every comment achieving it, sorted.

Maximum Class Total Over Two Consecutive Years

You are given a list of classes. Each class is represented as `[name, number_of_classes, start_year, end_year]`, meaning that class runs every calendar year from `start_year` through `end_year` (inclusive), contributing `number_of_classes` to each of those years. Compute the maximum total `number_of_classes` that occurs across any two consecutive calendar years (year y and year y+1 combined). A single year with no following active year is also a valid window (effectively pairing it with a year that contributes 0), so the answer is at least the busiest single year. Return 0 if there are no classes. Example: `[['Math', 3, 2020, 2021], ['Science', 2, 2021, 2022]]` -> year totals are 2020:3, 2021:5, 2022:2. The best consecutive pair is 2020+2021 = 8.

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

  1. Expand each class into the years it spans and accumulate per-year totals.
  2. Scan years in order; for each year y, the window value is total[y] + total[y+1].
  3. Initialize the answer with the busiest single year so a one-year span is covered.
Last updated: Jun 25, 2026

Loading coding console...

PracHub

Master your tech interviews with 9,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Choose the Cheapest Round Trip - Meta (medium)
  • Palindrome After Deleting at Most One Character - Meta (medium)
  • Validate Sorted Order Under a Custom Alphabet - Meta (medium)
  • Find Shortest Unique Prefixes - Meta (medium)
  • Compute Exclusive Execution Times - Meta (medium)