Stack,
Queue and Heap
Intermediate Level Questions:
Stack:
• Implement Stack using Queues
[Practice here: [Link] ]
• How to efficiently implement “k” stacks in an array ?
[Follow here: [Link] ]
• Design a Stack that supports getMin() in O(1) time and O(1)
extra space.
[Follow here: [Link]
o1-extra-space/ ]
• Implement stack and Queue using deque
[Follow here: [Link] ]
• Implement methods for Infix to Postfix, Prefix to Infix, Prefix to
Postfix, Postfix to Infix and Postfix to prefix Conversion using
stack.
[Follow here: [Link] ]
[Follow here: [Link] ]
[Follow here: [Link] ]
[Follow here: [Link] ]
[Follow here: [Link] ]
• Find the next Greater element
[Practice here: [Link] ]
• The celebrity Problem
[Practice here: [Link] ]
• Arithmetic Expression evaluation
[Practice here: [Link] ]
• Evaluation of Postfix expression
[Practice here: [Link] ]
• Implement a method to insert an element at its bottom without
using any other data structure.
• Reverse a stack using recursion
[Follow here: [Link] ]
• Sort a Stack using recursion
[Practice here: [Link] ]
• Merge Overlapping Intervals
[Practice here: [Link] ]
• Largest rectangular Area in Histogram
[Practice here: [Link]
histogram/0 ]
• Length of the Longest Valid Substring
[Practice here: [Link] ]
• Expression contains redundant bracket or not
[Follow here: [Link] ]
• Find the maximum difference between nearest left and right
smaller elements
[Practice here: [Link] ]
• Remove brackets from an algebraic string containing + and –
operators
[Follow here: [Link]
operators/ ]
• Implement a Simple text Editor using Stack
[Follow here: [Link]
[Link] ]
• Minimum number of bracket reversals needed to make an
expression balanced
[Practice here: [Link] ]
Queue:
• Implement Queue using Stack
[Practice here: [Link] ]
• LRU Cache Implementation
[Practice here: [Link] ]
• How to efficiently implement “k” queues in an array ?
[Follow here: [Link] ]
• Check if a queue an be sorted into another queue using a stack
[Practice here: [Link] ]
• Level Order Tree traversal
[Practice here: [Link] ]
• Reverse a Queue using recursion
[Practice here: [Link] ]
• Reverse the first “K” elements of a queue
[Practice here: [Link] ]
• Interleave the first half of the queue with second half
[Practice here: [Link] ]
• Sorting a queue without extra space
[Practice here: [Link] ]
• Find the first circular tour that visits all Petrol Pumps
[Practice here: [Link] ]
• Minimum time required to rot all oranges
[Practice here: [Link] ]
• Find maximum level sum in Binary tree
[Practice here: [Link] ]
• Distance of nearest cell having 1 in a binary matrix
[Practice here: [Link] ]
• First negative integer in every window of size “k”
[Practice here: [Link]
of-size-k/0 ]
• Check if all levels of two trees are anagrams or not.
[Practice here: [Link] ]
• Sum of minimum and maximum elements of all subarrays of size
“k”.
[Practice here: [Link] ]
• Minimum sum of squares of character counts in a given string after
removing “k” characters.
[Practice here: [Link] ]
• Queue based approach or first non-repeating character in a stream.
[Practice here: [Link]
stream/0 ]
Heap:
• Heap Sort
[Follow here: [Link] ]
• “k” largest element in an array
[Practice here: [Link] ]
• Kth smallest and largest element in an unsorted array
[Practice here: [Link] ]
• Check if a Binary Tree is Heap
[Practice here: [Link] ]
• Connect “n” ropes with minimum cost
[Practice here: [Link] ]
• Merge “K” sorted arrays.
[Practice here: [Link] ]
• Largest Derangement of a Sequence
[Practice here: [Link] ]
• Maximum distinct elements after removing “k” elements
[Practice here: [Link]
removing-k-elements/0 ]
• Median in a stream of Running Integers
[Practice here: [Link] ]
• Largest Triplet Product in a stream
[Practice here: [Link] ]
• Convert BST to Min Heap
[Practice here: [Link] ]
• Merge 2 Binary Max Heaps
[Practice here: [Link] ]
• Kth largest sum continuous subarrays
[Practice here: [Link] ]
• Convert min heap to max heap
[Practice here: [Link] ]
• Why is Binary Heap is preferred over BST for Priority Queue ?
[Answer: [Link] ]
• Given Level order traversal of a Binary Tree, check if the tree is
Min heap.
[Follow here: [Link]
heap/ ]
• Rearrange characters in a string such that no two adjacent are
same.
[Practice here: [Link] ]
• Minimum sum of two numbers formed from digits of an array
[Practice here: [Link] ]
• Leetcode- reorganize strings
[Practice here: [Link] ]
• Merge “K” Sorted Linked Lists
[Practice here: [Link] ]
• Smallest range in “K” Lists
[Practice here: [Link]
from-k-lists/1 ]