Skip to content
We areTOP 1%

Implement Queue using Stacks

EasyLeetCodeStack & Queue
Solve on LeetCode(opens in a new tab)
Track your progress
First attempt
Re-solve after a few days
Final pass before interviews
Approach hintTry it first, then reveal

Push into an input stack and pop from an output stack, moving everything from input to output only when output is empty. Each element moves at most once, so operations are amortised O(1).

More in Stack & Queue

Stack & Queue questions
#ProblemPlatformDifficultyOpen1st1st Visit2nd2nd VisitRevRevise
1Valid ParenthesesLeetCodeEasy Solve Valid Parentheses on LeetCode (opens in a new tab)
2Implement Queue using StacksLeetCodeEasy Solve Implement Queue using Stacks on LeetCode (opens in a new tab)
3Remove All Adjacent Duplicates In StringLeetCodeEasy Solve Remove All Adjacent Duplicates In String on LeetCode (opens in a new tab)
4Jzzhu and ChildrenCodeforcesEasy 1000Solve Jzzhu and Children on Codeforces (opens in a new tab)
5Move BracketsCodeforcesEasy 1000Solve Move Brackets on Codeforces (opens in a new tab)
6Social Network (easy version)CodeforcesEasy 1000Solve Social Network (easy version) on Codeforces (opens in a new tab)
7YetnotherrokenKeoardCodeforcesEasy 1000Solve YetnotherrokenKeoard on Codeforces (opens in a new tab)
8Even PositionsCodeforcesEasy 1100Solve Even Positions on Codeforces (opens in a new tab)
9Min StackLeetCodeMedium Solve Min Stack on LeetCode (opens in a new tab)
10Evaluate Reverse Polish NotationLeetCodeMedium Solve Evaluate Reverse Polish Notation on LeetCode (opens in a new tab)
11Asteroid CollisionLeetCodeMedium Solve Asteroid Collision on LeetCode (opens in a new tab)
12Decode StringLeetCodeMedium Solve Decode String on LeetCode (opens in a new tab)

Sign in to track your progress

Your checkboxes, streak and activity heatmap are saved to your account and sync across devices. It is free.
Sign in with email

New here? Create an account