PracHub
QuestionsCoachesLearningGuidesInterview Prep

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.

Return all stringified keys tied for highest frequency, preserving first appearance order, without using max or Counter.

Examples

Input: (['park', 'Park', 'McDonalds', 'apple', 'Apple Park', 'park', 'Park'],)

Expected Output: ['park', 'Park']

Explanation: Prompt example.

Input: ([],)

Expected Output: []

Explanation: Empty list.

Input: ([1, '1', 2, 2],)

Expected Output: ['1', '2']

Explanation: Stringification can merge values.

Input: (['a', 'b', 'a', 'b', 'c'],)

Expected Output: ['a', 'b']

Explanation: Tie by first appearance.

Hints

  1. Count manually, scan once for the best count, then scan original key order for ties.
Last updated: Jun 27, 2026

Loading coding console...

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
  • AI Coding 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.

Related Coding Questions

  • Minimum Cells to Bridge a Magic Grid - Apple (hard)
  • Find Common Prefix Across Strings - Apple (easy)
  • Find Minimum Processing Rate - Apple
  • Compute Earliest Bus Arrival - Apple (medium)
  • Find the Extra Edge - Apple (hard)