# Category Archives: Heap

## Scheduling priority tasks in limited time and minimizing loss

Given n tasks with arrival time, priority and number of time units they need. We need to schedule these tasks on a single resource. The… Read More »

## Adding elements of an array until every element becomes greater than or equal to k

We are given a list of N unsorted elements, we need to find minimum number of steps in which the elements of the list can… Read More »

## make_heap() in C++ STL

make_heap() is used to transform a sequence into a heap. A heap is a data structure which points to highest( or lowest) element and making… Read More »

## Leftist Tree / Leftist Heap

A leftist tree or leftist heap is a priority queue implemented with a variant of a binary heap. Every node has an s-value (or rank… Read More »

## Median of Stream of Running Integers using STL

Given that integers are being read from a data stream. Find median of all the elements read so far starting from the first integer till… Read More »

## Merge k sorted linked lists | Set 2 (Using Min Heap)

Given k sorted linked lists each of size n, merge them and print the sorted output. Examples: Input: k = 3, n = 4 list1… Read More »

## Largest triplet product in a stream

Given a stream of integers represented as arr[]. For each index i from 0 to n-1, print the multiplication of largest, second largest, third largest… Read More »

## Find k numbers with most occurrences in the given array

Given an array of n numbers and a positive integer k. The problem is to find k numbers with most occurrences, i.e., the top k… Read More »

## Convert BST to Min Heap

Given a binary search tree which is also a complete binary tree. The problem is to convert the given BST into a Min Heap with… Read More »

## Huffman Decoding

We have discussed Huffman Encoding in a previous post. In this post decoding is discussed. Examples: Input Data : AAAAAABCCCCCCDDEEEEE Frequencies : A: 6, B:… Read More »

## Merge two binary Max Heaps

Given two binary max heaps as arrays, merge the given heaps. Examples : Input : a = {10, 5, 6, 2}, b = {12, 7,… Read More »

## How to implement stack using priority queue or heap?

How to Implement stack using a priority queue(using min heap)?. Asked In: Microsoft, Adobe. Recommended: Please try your approach on {IDE} first, before moving on… Read More »

## Applications of Priority Queue

A Priority Queue is different from a normal queue, because instead of being a “first-in-first-out”, values come out in order by priority. It is an… Read More »

## Given level order traversal of a Binary Tree, check if the Tree is a Min-Heap

Given the level order traversal of a Complete Binary Tree, determine whether the Binary Tree is a valid Min-Heap Examples: Input : level = [10,… Read More »

## Amazon Interview Experience | Set 337 (For SDE-1)

Amazon Banglore/Chennai Interview for SDE 1 role Round 1 – Pen Paper Test 1) Root to leaf path sum equal to a given number, number… Read More »