PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches
|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)
PayPal logo
PayPal
Aug 13, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
6
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.

Comments (0)

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 7,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
  • Compare Platforms
  • Discord Community

Support

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

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.