Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Explain Heaps and Implement
00:00
5 left

Explain Heaps and Implement

MediumPython

Problem

Describe the heap (priority queue) data structure and implement it (e.g. insert and supporting operations).

Asked in the technical phone screen stage. This was a 45-minute online technical interview with a Verily engineer, with approximately 20 minutes allocated to describing and implementing a heap.

Contract

Implement heap_operations(operations). Each operation is ['insert', value], ['peek'], or ['extract_min']. Return the values produced by peek and extract_min, in order. Inputs will not peek or extract from an empty heap.

Constraints

  • 0 <= operations.length <= 10^4
  • Each operation is an insert, peek, or extract_min operation
  • insert values are integers in the range -10^9 to 10^9
  • peek and extract_min are called only when the heap is nonempty

Function Signature

def heap_operations(operations):
Interviewer

Your question is Explain Heaps and Implement. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.