PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCareers
|Home/Coding & Algorithms/Apple

Implement most frequent key without using max()

Last updated: Mar 29, 2026

Quick Overview

Category: Coding & Algorithms — this problem evaluates frequency counting, dictionary-based aggregation, string handling, manual maximum-finding without built-in functions, and stable tie-breaking by first appearance in the input.

  • medium
  • Apple
  • Coding & Algorithms
  • Analytics Engineer

Implement most frequent key without using max()

Company: Apple

Role: Analytics Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given the following Python class skeletons. The `Parent` class precomputes: - `self.l`: the original list - `self.lf`: a `set` of the stringified items in the list - `self.ldf`: a `dict[str, int]` mapping each stringified item to its frequency ```python class Parent: def __init__(self, l): self.l = l self.lf = set(str(s) for s in self.l) 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()`. - Do not use `collections.Counter`. - Find the highest count manually (via iteration). Output: - Return a `list[str]` of all keys that are tied for the highest frequency. - If multiple keys tie, return them in the order of first appearance in the original input 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()) ``` Expected output: ```text most frequent: ['park', 'Park'] ``` Implement `Child.most_frequent_key()`.

Quick Answer: Category: Coding & Algorithms — this problem evaluates frequency counting, dictionary-based aggregation, string handling, manual maximum-finding without built-in functions, and stable tie-breaking by first appearance in the input.

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
Dec 30, 2025, 12:00 AM
Analytics Engineer
Technical Screen
Coding & Algorithms
3
0

You are given the following Python class skeletons. The Parent class precomputes:

  • self.l : the original list
  • self.lf : a set of the stringified items in the list
  • self.ldf : a dict[str, int] mapping each stringified item to its frequency
class Parent:
    def __init__(self, l):
        self.l = l
        self.lf = set(str(s) for s in self.l)
        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()`.
        - Do not use `collections.Counter`.
        - Find the highest count manually (via iteration).

        Output:
        - Return a `list[str]` of all keys that are tied for the highest frequency.
        - If multiple keys tie, return them in the order of first appearance in the original input 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())

Expected output:

most frequent: ['park', 'Park']

Implement Child.most_frequent_key().

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Apple•More Analytics Engineer•Apple Analytics Engineer•Apple Coding & Algorithms•Analytics 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.