Stack Data Structure: Practice Problems and Interview Questions

Coding Freak
Techie Delight
Published in
2 min readDec 26, 2018


Stack (data structure)

A stack is a linear Last-In-Last-Out (LIFO) data structure which means that the last element added to the stack will be the first one to be removed. Therefore, once a new element is added to the stack, all elements that were added after it has to be removed before the new element can be removed.

In this post, we have listed out commonly asked interview questions that use stack data structure:

  1. Stack implementation using an array — C, C++, Java, Python
  2. Stack Implementation using a Linked List
  3. Implement a stack using the queue data structure
  4. Implement a queue using the stack data structure
  5. Design a stack that returns the minimum element in constant time
  6. Design a stack that returns a minimum element without using an auxiliary stack
  7. Implement two stacks in a single array
  8. Recursive solution to sort a stack
  9. Reverse a stack using recursion
  10. Reverse a string using a stack data structure
  11. Check if an expression is balanced or not
  12. Find duplicate parenthesis in an expression
  13. Evaluate a postfix expression
  14. Decode a given sequence to construct a minimum number without repeated digits
  15. Merging Overlapping Intervals
  16. Convert an infix expression into a postfix expression
  17. Find the next greater element for every element in a circular array
  18. Find the next greater element for every array element
  19. Find the previous smaller element for each array element
  20. Reverse an array in C++
  21. Longest Increasing Subsequence Problem
  22. Find all elements in an array that are greater than all elements to their right
  23. Iterative Implementation of Quicksort
  24. Find all binary strings that can be formed from a wildcard pattern
  25. Find the length of the longest balanced parenthesis in a string
  26. Reverse text without reversing individual words
  27. Reverse a string without using recursion
  28. Inorder Tree Traversal
  29. Preorder Tree Traversal
  30. Postorder Tree Traversal
  31. Check if two binary trees are identical or not
  32. Find ancestors of a given node in a binary tree
  33. Iteratively print the leaf to root path for every leaf node in a binary tree
  34. Find preorder traversal of a binary tree from its inorder and postorder sequence
  35. Construction of an expression tree
  36. Print complete Binary Search Tree (BST) in increasing order
  37. Depth First Search (DFS)
  38. Check whether the leaf traversal of given binary trees is the same or not
  39. Reverse level order traversal of a binary tree
  40. Invert Binary Tree
  41. Invert alternate levels of a perfect binary tree
  42. Depth-First Search (DFS) vs Breadth-First Search (BFS)

Thanks for reading.