PracHub
QuestionsCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Microsoft

Find Top K Largest Elements

Last updated: Jun 25, 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

  • In-Memory URL Shortener: Encode and Decode - Microsoft (medium)
  • Minimum Moves on a Grid with k-Cell Jumps - Microsoft (medium)
  • Find the Best Connected Strength for Every Tree Node - Microsoft (medium)
  • Maximize a Product After a Shared XOR - Microsoft (medium)
  • Return Top K Open Businesses - Microsoft (hard)
|Home/Coding & Algorithms/Microsoft

Find Top K Largest Elements

Microsoft logo
Microsoft
Feb 5, 2026, 12:00 AM
mediumMachine Learning EngineerTechnical ScreenCoding & Algorithms
2
0
Practice Read
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,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities

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.