Point OA Interview Problem: Python Book Popularity Tracker

17 Views
No Comments

Implement a Python application for managing a bookstore’s inventory. The application should allow adding books, finding highest-rated books, and recommending books by genre.

There are two classes:

  • Book class with attributes:
    • title (string): the book’s title
    • genre (string): the book’s genre
    • rating (float): the customer rating
  • LibraryManagement class with methods:
    • add_book(Book book): adds a new book to the inventory
    • get_highest_rated_books(int x): returns the x highest-rated books, sorted by rating (descending) and title (descending) for ties
    • recommend_top_book_by_genre(string genre): returns the highest-rated book in the specified genre, or None if no books exist in that genre

The code for reading input, calling methods, and producing output is already provided.

Constraint: The number of recommended books is less than or equal to the number of books in the book list.

This problem asks you to build a bookstore inventory manager with two main operations: retrieving the top-rated books globally and recommending the best book within a genre. A common approach is to store all books in a heap or sorted structure for the global top-x query, while keeping a hash map from genre to the current best book for fast genre-based recommendations. Pay close attention to tie-breaking: higher rating comes first, and if ratings are equal, compare titles consistently as required by the prompt.

END
 0