Stacks, queues and heaps interview questions
12 questions on this data structure, most asked first. Reported by candidates in public interview write-ups and reworded by Scrivio. How the reports are counted
Your progress: 0 of 12 done, 0 saved
Build a stack using only queue operations.
Reported 73 times
Read the solutionStacks and queuesExample sources
3 of the write-ups counted: geeksforgeeks.org 2022, geeksforgeeks.org 2019, geeksforgeeks.org 2017
Find the k-th largest element in an unsorted array.
Reported 55 times
Read the solutionHeaps and top kExample sources
3 of the write-ups counted: geeksforgeeks.org 2020, geeksforgeeks.org 2022, geeksforgeeks.org 2020
How does a stack differ from a queue?
Reported 53 times
Read the solutionData structure basicsExample sources
3 of the write-ups counted: geeksforgeeks.org 2024, geeksforgeeks.org 2024, geeksforgeeks.org 2023
Merge k sorted linked lists into a single sorted list.
Reported 34 times
Read the solutionHeaps and top kExample sources
3 of the write-ups counted: geeksforgeeks.org 2020, geeksforgeeks.org 2019, geeksforgeeks.org 2023
Keep track of the median of a stream of numbers as each new number arrives.
Reported 21 times
Read the solutionHeaps and top kExample sources
3 of the write-ups counted: geeksforgeeks.org 2018, geeksforgeeks.org 2020, geeksforgeeks.org 2014
Join n ropes into one, where each join costs the sum of the two lengths. Find the lowest total cost.
Reported 21 times
Read the solutionHeaps and top kExample sources
3 of the write-ups counted: geeksforgeeks.org 2021, geeksforgeeks.org 2021, geeksforgeeks.org 2020
For every element of an array, find the next greater element to its right.
Reported 20 times
Read the solutionStacks and queuesExample sources
3 of the write-ups counted: geeksforgeeks.org 2022, geeksforgeeks.org 2015, geeksforgeeks.org 2012
Given bar heights of a histogram, find the area of the largest rectangle it contains.
Reported 19 times
Read the solutionStacks and queuesExample sources
3 of the write-ups counted: geeksforgeeks.org 2023, geeksforgeeks.org 2024, geeksforgeeks.org 2017
For every window of k consecutive elements in an array, report the maximum.
Reported 19 times
Read the solutionSliding windowExample sources
3 of the write-ups counted: geeksforgeeks.org 2021, geeksforgeeks.org 2019, geeksforgeeks.org 2018
Implement a queue using two stacks.
Reported 18 times
Read the solutionStacks and queuesExample sources
3 of the write-ups counted: geeksforgeeks.org 2023, geeksforgeeks.org 2022, geeksforgeeks.org 2020
What is a stack, and which operations does it support?
Reported 18 times
Read the solutionData structure basicsExample sources
3 of the write-ups counted: geeksforgeeks.org 2021, geeksforgeeks.org 2020, geeksforgeeks.org 2022
Check whether a string of brackets is balanced.
Reported 15 times
Read the solutionStacks and queuesExample sources
3 of the write-ups counted: geeksforgeeks.org 2022, geeksforgeeks.org 2016, geeksforgeeks.org 2013