Skip to main content
Sproutern LogoSproutern
InterviewsGamesBlogToolsAbout
Sproutern LogoSproutern
Donate
Sproutern LogoSproutern

Your complete education and career platform. Access real interview experiences, free tools, and comprehensive resources to succeed in your professional journey.

Company

About UsContact UsSuccess StoriesOur MethodologyBlog❀️ Donate

For Students

Find InternshipsScholarshipsCompany ReviewsCareer ToolsFree ResourcesCollege PlacementsSalary Guide

🌍 Study Abroad

Country GuidesπŸ‡©πŸ‡ͺ Study in GermanyπŸ‡ΊπŸ‡Έ Study in USAπŸ‡¬πŸ‡§ Study in UKπŸ‡¨πŸ‡¦ Study in CanadaGPA Converter

Resources

Resume TemplatesCover Letter SamplesInterview Cheat SheetResume CheckerCGPA ConverterIT CertificationsDSA RoadmapInterview QuestionsFAQ

Legal

Privacy PolicyTerms & ConditionsCookie PolicyDisclaimerSitemap Support

Β© 2026 Sproutern. All rights reserved.

β€’

Made with ❀️ for students worldwide

Follow Us:
    ← DSA Roadmap
    πŸ“Š
    Topic #12

    Heap / Priority Queue

    Heaps efficiently find min/max elements. Essential for Top-K, merge K sorted lists, and scheduling problems.

    Time

    Insert: O(log n), Extract Min/Max: O(log n), Peek: O(1)

    Space

    O(n)

    Problems

    4 must-do

    Key Patterns

    Top K Elements
    Merge K Sorted Lists
    Two Heaps (Median)
    Scheduling
    Kth Smallest/Largest

    πŸ“‹ Must-Do Problems

    #ProblemDifficultyAsked At
    1Kth Largest Element in an Array
    Medium
    Google
    Meta
    Amazon
    2Merge K Sorted Lists
    Hard
    Google
    Amazon
    Microsoft
    3Find Median from Data Stream
    Hard
    Google
    Amazon
    Microsoft
    4Top K Frequent Elements
    Medium
    Amazon
    Google
    Meta

    πŸ’‘ Key Concepts

    1.

    Min-heap: parent ≀ children. Max-heap: parent β‰₯ children

    2.

    In Python: heapq (min-heap by default). For max-heap, negate values

    3.

    Two heaps pattern: max-heap for lower half, min-heap for upper half β†’ O(1) median

    4.

    Heap is NOT a sorted structure β€” only the root is guaranteed min/max

    Continue Practicing

    DSA Roadmap DSA Interview Q&A Practice Games