Quick Overview

This question evaluates skills in grouping and aggregation of items and constrained selection to maximize a numeric objective, reflecting competency in data manipulation and combinatorial optimization.

Compute maximum score using up to 3 categories

Company: Meta

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

## Problem A library runs a summer reading program. Each book a student reads earns a certain number of points, and each book belongs to a **category**. A student may score points from **at most 3 books**, with the restriction that the selected books must be from **distinct categories** (i.e., no two selected books can share the same category). Given a list of books the student read, compute the **maximum total score** the student can achieve. ### Input - `books`: a list of tuples `(category: str, points: int)` - The list may be empty. - Assume `points` are integers (typically non-negative). ### Output - Return an integer: the maximum achievable total points. ### Function signature (Python) ```python def get_max_score(books: list[tuple[str, int]]) -> int: ... ``` ### Examples / Tests ```python test1 = [ ("Adventure", 5), ("Adventure", 2), ("History", 3), ] assert get_max_score(test1) == 8 # 5 (Adventure) + 3 (History) test2 = [ ("Adventure", 4), ("History", 3), ("Reference", 1), ("Fiction", 2), ] assert get_max_score(test2) == 9 # 4 + 3 + 2 test3 = [ ("Biography", 2), ("Biography", 4), ("Science", 3), ("Science", 1), ] assert get_max_score(test3) == 7 # 4 + 3 test4 = [] assert get_max_score(test4) == 0 ``` ### Clarifications - You may pick 0, 1, 2, or 3 books (whichever maximizes the score). - You cannot pick more than one book from the same category.

Overview: This question evaluates skills in grouping and aggregation of items and constrained selection to maximize a numeric objective, reflecting competency in data manipulation and combinatorial optimization.

Read the full Meta Data Scientist interview experience this question came from

Pick at most one book per category and at most three books total to maximize score.

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 best per category.

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

Expected Output: 9

Explanation: Pick top three categories.

Hints

  1. Clarify edge cases before coding.
  2. Keep the return value deterministic.

Loading coding console...