PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Microsoft

Find Top K Largest Elements

Last updated: Apr 12, 2026

Quick Overview

This question evaluates a candidate's skill in algorithmic selection and data-structure usage for extracting top-k elements from large arrays, emphasizing time and space complexity considerations and correct handling of duplicate values.

  • medium
  • Microsoft
  • Coding & Algorithms
  • Machine Learning Engineer

Find Top K Largest Elements

Company: Microsoft

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Given an unsorted integer array `nums` of length `N` and an integer `k` such that `1 <= k <= N`, return the `k` largest elements in the array. If a value appears multiple times, treat each occurrence separately. You may return the result in any order. Assume `N` is much larger than `k`, so the goal is to design a solution that is more efficient than sorting the entire array when possible. Example: - Input: `nums = [7, 10, 4, 3, 20, 15]`, `k = 3` - Output: `[10, 15, 20]` Follow-up: If you choose a heap-based solution, explain whether a min-heap or a max-heap is the better choice and why.

Quick Answer: This question evaluates a candidate's skill in algorithmic selection and data-structure usage for extracting top-k elements from large arrays, emphasizing time and space complexity considerations and correct handling of duplicate values.

Related Interview Questions

  • Return Top K Open Businesses - Microsoft (hard)
  • Implement Memory Allocation and In-Memory Records - Microsoft (medium)
  • Implement K-Means and Detect Divisible Subarrays - Microsoft (medium)
  • Sort Three Categories In Place - Microsoft (medium)
  • Retain Top K Elements - Microsoft (medium)
Microsoft logo
Microsoft
Feb 5, 2026, 12:00 AM
Machine Learning Engineer
Technical Screen
Coding & Algorithms
2
0
Loading...

Given an unsorted integer array nums of length N and an integer k such that 1 <= k <= N, return the k largest elements in the array. If a value appears multiple times, treat each occurrence separately. You may return the result in any order.

Assume N is much larger than k, so the goal is to design a solution that is more efficient than sorting the entire array when possible.

Example:

  • Input: nums = [7, 10, 4, 3, 20, 15] , k = 3
  • Output: [10, 15, 20]

Follow-up: If you choose a heap-based solution, explain whether a min-heap or a max-heap is the better choice and why.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Microsoft•More Machine Learning Engineer•Microsoft Machine Learning Engineer•Microsoft Coding & Algorithms•Machine Learning Engineer Coding & Algorithms
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
  • Compare Platforms
  • Discord Community

Support

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

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.