Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Queue using Linked List

Easy Acceptance 45.60% Points 20.00

Implement a Queue using Linked List.

A Query Q is of 2 Types

  1. 1 x (a query of this type means pushing 'x' into the queue)
  2. 2 (a query of this type means to pop an element from the queue and print the popped element)
Examples
Example 1

Example 1

Input: Q = 5, Queries = 1 2 1 3 2 1 4 2

Output: 2 3

Explanation: n the first testcase. 1 2 the queue will be {2}. 1 3 the queue will be {2 3}. 2 poped element will be 2 the queue will be {3}. 1 4 the queue will be {3 4}. 2 poped element will be 3.

Hints
Hint 1
Expected Time Complexity: O(1).
Hint 2
Expected Auxiliary Space: O(1).
Constraints
  • 1 <= Q <= 100
  • 1 <= x <= 100
Companies
Microsoft Apple Walmart
Topics
Queue
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions