FastPrepImplement a Heap Priority Queue
Problems/Implement a Heap Priority Queue

Implement a Heap Priority Queue

ByteDance logoByteDance● MediumNEW GRADPHONE SCREEN

Updated Oct 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The interview report names a heap-priority-queue implementation but omits heap direction, supported operations, duplicate handling, and empty-queue behavior. This practice uses a finite min-priority-queue sequence with push, peek, and pop operations; every observation is valid and duplicate priorities remain separate entries. Approximate source match: 72%.

Implement a min-priority queue of integers without using a built-in priority-queue or heap data structure. Process operations from left to right:

  • PUSH inserts values[i].
  • PEEK returns the current minimum without removing it.
  • POP removes 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, or POP.
  • Every PEEK and POP occurs 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
All ByteDance interview questionsSee ByteDance hiring insights
Saved
class Solution {
    public int[] runPriorityQueue(String[] operations, int[] values) {
      // write your code here
    }
}
Checking account…