PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCareers
|Home/Coding & Algorithms/Apple

Implement most_frequent_key without using max()

Last updated: Mar 29, 2026

Quick Overview

This question evaluates proficiency in Python fundamentals and object-oriented inheritance, focusing on frequency aggregation using a precomputed dictionary, iteration over mappings, and correct handling of ties and empty inputs.

  • easy
  • Apple
  • Coding & Algorithms
  • Data Engineer

Implement most_frequent_key without using max()

Company: Apple

Role: Data Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

## Problem (Python OOP) You are given two classes. `Parent` precomputes frequency counts of items (as strings) from an input list. ```python class Parent: def __init__(self, l): self.l = l # set of all unique string forms self.lf = set(str(s) for s in self.l) # dict: key -> count self.ldf = {} for item in self.l: s = str(item) if s not in self.ldf: self.ldf[s] = 1 else: self.ldf[s] += 1 class Child(Parent): def most_frequent_key(self): """Return the key(s) with the highest frequency. Constraints: - You may NOT use Python's built-in `max()`. - Use the precomputed `self.ldf` from `Parent`. Return: - A list of the most frequent key(s) (strings). If there is a tie, include all tied keys. - If the input list is empty, return an empty list. """ # TODO: implement return output_list ``` ### Example ```python queries = ['park', 'Park', 'McDonalds', 'apple', 'Apple Park', 'park', 'Park'] x = Child(queries) print("most frequent:", x.most_frequent_key()) ``` **Notes/clarifications** - Counting is case-sensitive because keys are created via `str(item)`. - The goal is to manually compute the highest frequency via iteration (no `max()`).

Quick Answer: This question evaluates proficiency in Python fundamentals and object-oriented inheritance, focusing on frequency aggregation using a precomputed dictionary, iteration over mappings, and correct handling of ties and empty inputs.

Related Interview Questions

  • Compute Earliest Bus Arrival - Apple (medium)
  • Find the Extra Edge - Apple (hard)
  • Rotate a Matrix In Place - Apple (medium)
  • Encode and Rebuild a Binary Tree - Apple (hard)
  • Wrap Matching Substrings in Bold Tags - Apple (medium)
Apple logo
Apple
Nov 16, 2025, 12:00 AM
Data Engineer
Technical Screen
Coding & Algorithms
7
0

Problem (Python OOP)

You are given two classes. Parent precomputes frequency counts of items (as strings) from an input list.

class Parent:
    def __init__(self, l):
        self.l = l
        # set of all unique string forms
        self.lf = set(str(s) for s in self.l)

        # dict: key -> count
        self.ldf = {}
        for item in self.l:
            s = str(item)
            if s not in self.ldf:
                self.ldf[s] = 1
            else:
                self.ldf[s] += 1


class Child(Parent):
    def most_frequent_key(self):
        """Return the key(s) with the highest frequency.

        Constraints:
        - You may NOT use Python's built-in `max()`.
        - Use the precomputed `self.ldf` from `Parent`.

        Return:
        - A list of the most frequent key(s) (strings). If there is a tie, include all tied keys.
        - If the input list is empty, return an empty list.
        """
        # TODO: implement
        return output_list

Example

queries = ['park', 'Park', 'McDonalds', 'apple', 'Apple Park', 'park', 'Park']

x = Child(queries)
print("most frequent:", x.most_frequent_key())

Notes/clarifications

  • Counting is case-sensitive because keys are created via str(item) .
  • The goal is to manually compute the highest frequency via iteration (no max() ).

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Apple•More Data Engineer•Apple Data Engineer•Apple Coding & Algorithms•Data Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • Careers
  • 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.