Implement a Heap Priority Queue
Updated
Problem statement
Implement a min-priority queue of integers without using a built-in priority-queue or heap data structure. Process operations from left to right:
PUSHinsertsvalues[i].PEEKreturns the current minimum without removing it.POPremoves and returns the current minimum.
Collect and return every value produced by PEEK or POP, in operation order. Every PEEK and POP occurs while the queue is nonempty. Equal values are allowed. Ignore values[i] for PEEK and POP.
Function
runPriorityQueue(operations: String[], values: int[]) → int[]Examples
Example 1
operations = ["PUSH","PUSH","PEEK","POP","PEEK"]values = [5,2,0,0,0]return = [2,2,5]The minimum after both insertions is 2. POP returns and removes 2, leaving 5.
Example 2
operations = ["PUSH","PUSH","PUSH","POP","POP","POP"]values = [3,3,1,0,0,0]return = [1,3,3]Repeated values remain separate queue entries and are removed in nondecreasing priority order.
Example 3
operations = ["PUSH","PEEK","PUSH","PEEK"]values = [-4,0,-7,0]return = [-4,-7]The second insertion becomes the new minimum.
Constraints
1 <= operations.length == values.length <= 200000.- Each operation is
PUSH,PEEK, orPOP. - Every
PEEKandPOPoccurs when the queue is nonempty. - Each inserted value is a signed 32-bit integer.
More ByteDance Phone Screen questions
- Largest Number Below N from Reusable DigitsPHONE SCREEN · Seen Nov 2026
- Log Analyzer: Busiest Service in a Rolling WindowPHONE SCREEN · Seen Nov 2026
- Majority ElementPHONE SCREEN · Seen Nov 2026
- Valid ParenthesesPHONE SCREEN · Seen Nov 2026
- Binary Tree Target-Sum PathsPHONE SCREEN · Seen Nov 2026
- Longest Increasing SubsequencePHONE SCREEN · Seen Nov 2026
- Alien DictionaryPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Lexicographically Smallest Topological OrderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Maximum Number of Events That Can Be AttendedPHONE SCREEN · Seen Nov 2026
- Implement Multi-Head AttentionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Alert Engine with a Repeat IntervalChronosphere · PHONE SCREEN
- Timer Job Scheduler Wake-upsRedNote · PHONE SCREEN
- Key-Value Store on a Block DeviceLambda · PHONE SCREEN
- Lazy K-Way Union IteratorMongoDB · PHONE SCREENMongoDB interview questions
- Design Authentication ManagerApple · PHONE SCREENApple interview questions
- LLM Provider Pool FailoverPerplexity AI · PHONE SCREENPerplexity AI interview questions
- Periodic Event LoopEtched · PHONE SCREEN
- ID Allocator with Assign and ReleaseSnap Inc. · PHONE SCREENSnap Inc. interview questions
- 15-Minute Chat Session TrackerOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Capacity-Limited Timed CacheNetflix · PHONE SCREENNetflix interview questions
ByteDance interview experiences
- ByteDance TikTok USDS SWE Intern Interview: 1 Experience
- ByteDance MLE New Grad Interviews: 1 Experience
- ByteDance Security SRE Intern Phone Screens: 1 Experience
- ByteDance USDS New Grad SWE Phone Screen: 1 Experience
- ByteDance New Grad Data Engineer Video Interviews: 1 Experience
- ByteDance Trust & Safety Research Scientist Intern: 1 Experience