Skip to main content
Intermediatecoding Verified

How would you implement a priority queue? Compare a binary heap with other options.

ReportedSource: GeeksforGeeks interview experience: Snowflake on-campus 2020

Quick answerFree

Binary heap in an array: push = append + sift up, pop = move last to root + sift down, both O(log n), peek O(1), heapify O(n). Sorted list / BST / unsorted list trade insert vs pop cost.

Detailed answer· ~140 words

Interview Prep

Unlock the full answer with Interview Prep

Get a ~140-word model answer and a runnable reference solution, plus 61 more DSA questions.

Also in Pro (₹499 / 90 days).

Reference solution· runs in the browser sandbox

Interview Prep
Unlock with Interview Prep

+ 61 more DSA questions in Interview Prep, each with the full answer.

Discussion