PracHub
QuestionsCoachesLearningGuidesInterview Prep

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.

  • easy
  • Meta
  • Coding & Algorithms
  • Data Scientist

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.

Quick Answer: 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.

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.

Input: ([],)

Expected Output: 0

Explanation: No books gives zero.

Hints

  1. Clarify edge cases before coding.
  2. Keep the return value deterministic.
Last updated: Jun 27, 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
  • 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

  • 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)