Quick Overview

This Coding & Algorithms question in the Data Engineer domain evaluates grouping and top‑k aggregation concepts, testing the ability to combine per-category aggregation with selection under a uniqueness constraint.

Compute Max Score From Up to 3 Categories

Company: Meta

Role: Data Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Technical Screen

You are implementing a scoring function for a library summer reading program. Each book a student read is represented as a tuple `(category: str, points: int)`. Rules: - The student may count points from **at most 3 books**. - Any counted books must be from **distinct categories** (i.e., you can pick **at most one book per category**). - The student may pick fewer than 3 books if fewer categories exist. Task: Implement the function: ```python from typing import List, Tuple def get_max_score(books: List[Tuple[str, int]]) -> int: """Return the maximum total points achievable under the rules.""" ``` Examples: ```python test1 = [ ("Adventure", 5), ("Adventure", 2), ("History", 3), ] # Pick Adventure(5) + History(3) = 8 assert get_max_score(test1) == 8 test2 = [ ("Adventure", 4), ("History", 3), ("Reference", 1), ("Fiction", 2), ] # Pick top 3 categories: 4 + 3 + 2 = 9 assert get_max_score(test2) == 9 test3 = [ ("Biography", 2), ("Biography", 4), ("Science", 3), ("Science", 1), ] # Pick Biography(4) + Science(3) = 7 assert get_max_score(test3) == 7 test4 = [] assert get_max_score(test4) == 0 ``` Constraints: assume `len(books)` can be large, so your solution should be efficient (better than trying all combinations).

Quick Answer: This Coding & Algorithms question in the Data Engineer domain evaluates grouping and top‑k aggregation concepts, testing the ability to combine per-category aggregation with selection under a uniqueness constraint.

Pick at most one book from each category and at most three books total to maximize points.

Constraints

  • Inputs are Python literals matching the function signature.
  • Return a deterministic exact-match value.

Examples

Input: ([("Adventure",5),("Adventure",2),("History",3)],)

Expected Output: 8

Explanation: Pick the best book per category.

Input: ([("Adventure",4),("History",3),("Reference",1),("Fiction",2)],)

Expected Output: 9

Explanation: Pick the top three categories.

Hints

  1. Clarify edge cases before coding.
  2. Keep outputs deterministic when several valid answers exist.

Loading coding console...