PracHub
QuestionsCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/PayPal

Find k most frequent in linear time

Last updated: Mar 29, 2026

Quick Overview

This question evaluates a candidate's ability to design and analyze efficient frequency-counting algorithms and related data structures, testing competencies in hashing, bucket-based grouping, heap usage, and time/space complexity reasoning.

  • medium
  • PayPal
  • Coding & Algorithms
  • Software Engineer

Find k most frequent in linear time

Company: PayPal

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Given an integer array nums and an integer k (1 ≤ k ≤ number of distinct values in nums), return any k values that appear most frequently. Implement an average-case O(n) time, O(n) space solution using a frequency map and bucket-based grouping; explain why it is linear. Then compare it with a heap-based O(n log k) approach: discuss when each is preferable, memory trade-offs, and how you would break ties. Clarify handling of negative numbers and very large value ranges. Provide code and analyze time and space complexity.

Quick Answer: This question evaluates a candidate's ability to design and analyze efficient frequency-counting algorithms and related data structures, testing competencies in hashing, bucket-based grouping, heap usage, and time/space complexity reasoning.

Related Interview Questions

  • Minimize a String Using Allowed Swaps - PayPal (medium)
  • Compute variance of a list in Python - PayPal (easy)
  • Explain list vs tuple in Python - PayPal (easy)
  • Solve common search/parse/graph frequency tasks - PayPal (medium)
  • Explain differences between Python list and tuple - PayPal (hard)
|Home/Coding & Algorithms/PayPal

Find k most frequent in linear time

PayPal logo
PayPal
Aug 13, 2025, 12:00 AM
mediumSoftware EngineerTechnical ScreenCoding & Algorithms
7
0

Given an integer array nums and an integer k (1 ≤ k ≤ number of distinct values in nums), return any k values that appear most frequently. Implement an average-case O(n) time, O(n) space solution using a frequency map and bucket-based grouping; explain why it is linear. Then compare it with a heap-based O(n log k) approach: discuss when each is preferable, memory trade-offs, and how you would break ties. Clarify handling of negative numbers and very large value ranges. Provide code and analyze time and space complexity.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More PayPal•More Software Engineer•PayPal Software Engineer•PayPal Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ 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.