PracHub
QuestionsPremiumCoachesLearningGuidesInterview 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.

Input: (975312468,)

Expected Output: 13579

Explanation: Odd digits 9,7,5,3,1 sorted ascending form 13579.

Input: (0,)

Expected Output: -1

Explanation: 0 is even; no odd digits, so -1.

Input: (7,)

Expected Output: 7

Explanation: Single odd digit returns itself.

Input: (-531,)

Expected Output: 135

Explanation: Sign is ignored; odd digits 5,3,1 sorted form 135.

Input: (113355,)

Expected Output: 113355

Explanation: All digits already odd; sorted ascending stays 113355.

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.

Input: ({},)

Expected Output: []

Explanation: No stores -> empty result.

Input: ({'Solo': ['repeat', 'repeat', 'repeat', 'unique']},)

Expected Output: ['repeat', 'unique']

Explanation: In one store, 'repeat' dedups to count 1, same as 'unique'; both tie.

Input: ({'A': ['p', 'q'], 'B': ['q', 'r'], 'C': ['r', 'p']},)

Expected Output: ['p', 'q', 'r']

Explanation: Each of p, q, r appears in exactly 2 stores, all tied at count 2.

Input: ({'A': ['hello'], 'B': ['hello'], 'C': ['world']},)

Expected Output: ['hello']

Explanation: 'hello' is in 2 stores, 'world' in 1; 'hello' wins.

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.

Input: ([],)

Expected Output: 0

Explanation: No classes -> 0.

Input: ([['A', 4, 2020, 2020], ['B', 6, 2021, 2021]],)

Expected Output: 10

Explanation: 2020:4 and 2021:6 are consecutive, combined 10.

Input: ([['A', 1, 2020, 2020], ['B', 1, 2025, 2025]],)

Expected Output: 1

Explanation: Years 2020 and 2025 are not consecutive; best window is a single year = 1.

Input: ([['Long', 2, 2018, 2022]],)

Expected Output: 4

Explanation: Each of 2018..2022 has total 2; any consecutive pair sums to 4.

Input: ([['A', 3, 2020, 2021], ['B', 3, 2020, 2021], ['C', 10, 2020, 2020]],)

Expected Output: 22

Explanation: 2020: 3+3+10 = 16, 2021: 3+3 = 6; best pair 16+6 = 22.

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 8,000+ real questions from top companies.

Product

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

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL 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

  • Find Shortest Unique Prefixes - Meta (medium)
  • Compute Exclusive Execution Times - Meta (medium)
  • Solve Tree Columns And Maze Variants - Meta (medium)
  • Solve Tree Diameter and Palindromic Counts - Meta (medium)
  • Simulate Monster Team Battles - Meta (hard)