Implement a queue using the stack data structure
This post will implement a queue using the stack data structure. In other words, design a queue that supports enqueue and dequeue operations using standard push and pop operations of the stack.
Ace your Coding Interview
Get hired by top tech companies with our comprehensive interview preparation.
Get StartedThis post will implement a queue using the stack data structure. In other words, design a queue that supports enqueue and dequeue operations using standard push and pop operations of the stack.
Write an efficient algorithm to find a binary tree’s preorder traversal from its inorder and postorder sequence without constructing the tree.
Find all n–digit numbers with an equal sum of digits at even and odd index, where n varies from 1 to 9.
Calculate the total number of ways to achieve a given sum with n throws of dice having k faces.
Given a binary tree, count all subtrees in it such that every node in the subtree has the same value.
Given a BST, find the inorder successor of a given key in it. If the given key does not lie in the BST, then return the next greater key (if any) present in the BST.
Given a binary tree, write an efficient algorithm to find the maximum sum path between any two leaves in it.
Given a binary tree, write an efficient algorithm to find all nodes present at a given distance from any leaf node. We need to find only those nodes that are present in the root-to-leaf path for that leaf.
Given a binary tree that is only one swap away from becoming a BST, convert it into a BST in a single traversal.
Given a binary search tree, modify it such that every key is updated to contain the sum of all greater keys present in the BST.
Given a positive integer n, print all combinations of numbers between 1 and n having sum n.
Print binary representation of a given number in C, C++, Java, and Python using built-in methods and custom routines.