Solvarch
DSA ProblemsProgressPlanRoadmapsReviewCheat SheetsCompaniesSystem DesignCS FundamentalsQuestion Bank
Theme
Problems

Implement Queue using Stacks

Easy
stackqueuedesign

Implement a FIFO queue using only two stacks.

Input: one operation per line —

  • push x — enqueue integer x
  • pop — dequeue and print the front
  • peek — print the front
  • empty — print true/false

Output: one line per operation — push prints null; the others print their result.

Example 1
Input:
push 1
push 2
peek
pop
empty
Output:
null
null
1
1
false

Constraints

  • Up to 100 operations; pop/peek are always valid.
Watch a video walkthrough

Run your code against the sample tests, or Submit to run the full suite.