PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/HBO

Implement Director awards with Python OOP

Last updated: Mar 29, 2026

Quick Overview

This question evaluates proficiency in Python object-oriented programming, specifically correct use of @property, @classmethod, and @staticmethod, safe handling of mutable defaults and encapsulation of internal state, and design decisions around equality and hashing.

  • medium
  • HBO
  • Coding & Algorithms
  • Data Scientist

Implement Director awards with Python OOP

Company: HBO

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Take-home Project

You are given a simple hierarchy where Director extends Cast. Implement a robust, testable solution that avoids common Python pitfalls and demonstrates correct use of @property, @classmethod, and @staticmethod. Starting point: class Cast: def __init__(self, actors: list[str]): self.actors = list(actors) class Director(Cast): def __init__(self, name: str, actors: list[str], movies: list[str]): super().__init__(actors) self.name = name self.movies = list(movies) self._awards: list[tuple[str,int]] = [] # (award_name, year) Tasks: 1) Implement add_award(award_name: str, year: int) that appends a new (award_name, year) pair only if it does not already exist for this director (idempotent). Ensure no mutable-default arguments and that self._awards cannot be mutated from outside the class. 2) Add a property awards that returns an immutable, chronologically sorted view of awards; add a property latest_award that returns Optional[tuple[str,int]]. 3) Add a @staticmethod validate_award(award_name: str, year: int) that raises ValueError for empty names or years outside [1900, current_year]. Use it inside add_award. 4) Add a @classmethod from_filmography(cls, name: str, filmography: dict) that constructs a Director from {'actors': [...], 'movies': [...]}. Show how subclassing would work if you later create an AwardWinningDirector that adds fields like guild_membership. 5) Implement __eq__ and __hash__ so that two Director instances with the same name compare equal. Explain the trade-offs of this choice. 6) Provide a short doctest-style example demonstrating creation, adding duplicate awards, and the latest_award property.

Quick Answer: This question evaluates proficiency in Python object-oriented programming, specifically correct use of @property, @classmethod, and @staticmethod, safe handling of mutable defaults and encapsulation of internal state, and design decisions around equality and hashing.

HBO logo
HBO
Oct 13, 2025, 9:49 PM
Data Scientist
Take-home Project
Coding & Algorithms
0
0

Python OOP Exercise: Director extends Cast

Context

You are working with a simple class hierarchy where Director extends Cast. Implement a robust, testable Python solution that uses @property, @classmethod, and @staticmethod correctly, and avoids common pitfalls such as mutable defaults and leaking internal mutable state.

Starting point:

class Cast:
    def __init__(self, actors: list[str]):
        self.actors = list(actors)

class Director(Cast):
    def __init__(self, name: str, actors: list[str], movies: list[str]):
        super().__init__(actors)
        self.name = name
        self.movies = list(movies)
        self._awards: list[tuple[str,int]] = []  # (award_name, year)

Tasks

  1. Implement add_award(award_name: str, year: int) that appends a new (award_name, year) pair only if it does not already exist for this director (idempotent). Ensure no mutable-default arguments and that self._awards cannot be mutated from outside the class.
  2. Add a property awards that returns an immutable, chronologically sorted view of awards; add a property latest_award that returns Optional[tuple[str,int]].
  3. Add a @staticmethod validate_award(award_name: str, year: int) that raises ValueError for empty names or years outside [1900, current_year]. Use it inside add_award.
  4. Add a @classmethod from_filmography(cls, name: str, filmography: dict) that constructs a Director from {'actors': [...], 'movies': [...]}. Show how subclassing would work if you later create an AwardWinningDirector that adds fields like guild_membership.
  5. Implement eq and hash so that two Director instances with the same name compare equal. Explain the trade-offs of this choice.
  6. Provide a short doctest-style example demonstrating creation, adding duplicate awards, and the latest_award property.

Solution

Show

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More HBO•More Data Scientist•HBO Data Scientist•HBO Coding & Algorithms•Data Scientist Coding & Algorithms
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
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.