Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Max Points With Category Constraints

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Max Points With Category Constraints. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Meta AI is evaluating a reading list where each book has a category and a recommendation-point value. Given a dictionary of books, choose exactly three books whose categories are all different and return the maximum total points.

Formal Specification

Implement max_points_three_categories(books). The input books is a dictionary mapping a unique book ID to a dictionary with two fields: category, a string, and points, an integer. The function must return an integer representing the greatest possible sum of points from three books with pairwise-distinct categories. You may not select the same book more than once.

The input always contains at least three distinct categories, so a valid selection exists. The result depends only on the highest-point book in each category.

Constraints

  • 3 <= len(books) <= 10^6
  • Each book ID is unique
  • Each category is a non-empty string
  • -10^9 <= points <= 10^9
  • At least three distinct categories exist

Function Signature

def max_points_three_categories(books):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output