Implement a Queue using an Array. Queries in the Queue are of the following type:
(i) 1 x   (a query of this type means  pushing 'x' into the queue)
(ii) 2     (a query of this type means to pop element from queue and print the poped element)
Example 1:
Input:
Q = 5
Queries = 1 2 1 3 2 1 4 2
Output: 2 3
Explanation:
In the first test case for query 
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 
Example 2:
Input:
Q = 4
Queries = 1 3 2 2 1 4   
Output: 3 -1
Explanation:
In the second testcase for query 
1 3 the queue will be {3}
2   poped element will be 3 the
    queue will be empty
2   there is no element in the
    queue and hence -1
1 4 the queue will be {4}. 
Your Task :
You are required to complete the two methods push() which take one argument an integer 'x' to be pushed into the queue and pop() which returns a integer poped out from othe queue. If the queue is empty, it should return -1 on a pop operation. 
Expected Time Complexity: O(1) for both push() and pop().
Expected Auxiliary Space: O(1) for both push() and pop().
Constraints:
1 ≤ Q ≤ 10^{5}
1 ≤ x ≤ 10^{5}

Source: geeksforgeeks | Difficulty: EASY
Tags: Data structures

Starter code: #User function Template for python3

class MyQueue:
    
    #Function to push an element x in a queue.
    def push(self, x):
         
         #add code here
     
    #Function to pop an element from queue and return that element.
    def pop(self): 
         
         # add code here

Solutions:
class MyQueue:

	def __init__(self):
		self.arr = []

	def push(self, x):
		self.arr.append(x)
		return self.arr

	def pop(self):
		if len(self.arr) == 0:
			return -1
		if len(self.arr) > 0:
			return self.arr.pop(0)


class MyQueue:

	def __init__(self):
		self.queue = []

	def push(self, x):
		self.queue.append(x)

	def pop(self):
		if self.queue:
			return self.queue.pop(0)
		return -1


class MyQueue:

	def __init__(self):
		self.queue = list()
		self.maxSize = 100005
		self.head = 0
		self.tail = 0

	def push(self, data):
		if self.size() >= self.maxSize:
			return 'Queue Full'
		self.queue.append(data)
		self.tail += 1
		return

	def pop(self):
		if self.size() <= 0:
			self.resetQueue()
			return -1
		data = self.queue[self.head]
		self.head += 1
		return data

	def size(self):
		return self.tail - self.head

	def resetQueue(self):
		self.tail = 0
		self.head = 0
		self.queue = list()


class MyQueue:

	def __init__(self):
		self.queue = []

	def push(self, x):
		self.queue.append(x)

	def pop(self):
		if len(self.queue):
			a = self.queue.pop(0)
			return a
		else:
			return -1


class MyQueue:

	def __init__(self):
		self.MyQueue = []
		self.front = 0
		self.rear = 0

	def push(self, x):
		self.MyQueue.append(x)
		self.rear += 1

	def pop(self):
		if self.front == self.rear:
			return -1
		x = self.MyQueue[self.front]
		self.front += 1
		return x


class MyQueue(object):

	def __init__(self):
		self.stack = []

	def push(self, data):
		self.stack.append(data)

	def pop(self):
		if self.stack:
			return self.stack.pop(0)
		return -1


class MyQueue:

	def __init__(self):
		self.queue = []
		self.rear = 0
		self.front = 0

	def push(self, x):
		self.queue.append(x)
		self.rear += 1

	def pop(self):
		if self.front == self.rear:
			return -1
		else:
			temp = self.front
			self.front += 1
			return self.queue[temp]


class MyQueue:

	def __init__(self):
		self.Que = []

	def push(self, x):
		self.Que.append(x)

	def pop(self):
		if len(self.Que):
			e = self.Que.pop(0)
			return e
		else:
			return -1

	def isEmpty(self):
		if len(self.Que):
			return True
		else:
			return False


class MyQueue:

	def __init__(self):
		self.l = []

	def push(self, x):
		self.l.append(x)

	def pop(self):
		return self.l.pop(0) if self.l else -1


class MyQueue:

	def __init__(self):
		self.q = []

	def push(self, x):
		self.q.append(x)

	def pop(self):
		if len(self.q) == 0:
			return -1
		ans = self.q[0]
		self.q.pop(0)
		return ans


class MyQueue:

	def __init__(self):
		self.queue = list()
		self.maxSize = 100005
		self.head = 0
		self.tail = 0

	def push(self, x):
		if self.size() >= self.maxSize:
			return 'QueueFull'
		self.queue.append(x)
		self.tail += 1
		return

	def pop(self):
		if self.size() <= 0:
			self.resetQueue()
			return -1
		x = self.queue[self.head]
		self.head += 1
		return x

	def size(self):
		return self.tail - self.head

	def resetQueue(self):
		self.tail = 0
		self.head = 0
		self.queue = list()


class MyQueue:

	def __init__(self):
		self.y = [0] * 100000
		self.f = self.r = 0
		self.s = 0

	def push(self, x):
		self.y[self.r] = x
		self.r += 1
		self.s += 1

	def pop(self):
		if self.s != 0:
			res = self.y[self.f]
			self.f += 1
			self.s -= 1
			return res
		else:
			return -1


class MyQueue:

	def __init__(self):
		self.y = [0] * 100000
		self.front = 0
		self.rear = 0
		self.size = 0

	def push(self, x):
		self.y[self.rear] = x
		self.rear = self.rear + 1
		self.size = self.size + 1

	def pop(self):
		if self.size != 0:
			res = self.y[self.front]
			self.front = self.front + 1
			self.size = self.size - 1
			return res
		else:
			return -1


class MyQueue:
	arr = []
	isEmpty = False
	element = -1

	def push(self, x):
		if self.isEmpty:
			self.arr = []
		self.arr.append(x)
		self.isEmpty = False

	def pop(self):
		if len(self.arr) > 1:
			self.element = self.arr[0]
			self.arr.remove(self.element)
		elif len(self.arr) == 1:
			self.element = self.arr[0]
			self.arr[0] = -1
			self.isEmpty = True
		return self.element

	def isEmpty():
		return self.isEmpty


class MyQueue:

	def __init__(self):
		self.que = []

	def push(self, el):
		self.que.append(el)

	def pop(self):
		if self.que == []:
			return -1
		else:
			return self.que.pop(0)


class Node:

	def __init__(self, data):
		self.next = None
		self.data = data
		self.prev = None

class MyQueue:

	def __init__(self):
		self.head = None
		self.rear = None

	def push(self, el):
		box = Node(el)
		if self.head is None:
			self.head = box
			self.rear = box
			return
		self.head.prev = box
		box.next = self.head
		self.head = box

	def pop(self):
		if self.rear is None:
			return -1
		elif self.rear.prev is None:
			el = self.rear.data
			self.rear = self.head = None
			return el
		el = self.rear.data
		prev = self.rear.prev
		self.rear.prev = None
		self.rear = prev
		self.rear.next = None
		return el


class MyQueue:

	def __init__(self):
		self.arr = list()
		self.head = 0
		self.tail = 0
		self.maxl = 100003

	def push(self, x):
		if self.size() >= self.maxl:
			return -1
		self.arr.append(x)
		self.tail += 1

	def pop(self):
		if self.size() <= 0:
			self.reset()
			return -1
		data = self.arr[self.head]
		self.head += 1
		return data

	def size(self):
		return self.tail - self.head

	def reset(self):
		self.arr = []
		self.head = self.tail = 0


class MyQueue:

	def __init__(self):
		self.c = []

	def push(self, x):
		a = self.c
		a.append(x)
		return a

	def pop(self):
		b = len(self.c)
		if b == 0:
			return -1
		else:
			return self.c.pop(0)


class MyQueue:

	def __init__(self):
		self.arr = []

	def push(self, x):
		self.arr.append(x)

	def pop(self):
		if len(self.arr) > 0:
			popped = self.arr[0]
			del self.arr[0]
			return popped
		else:
			return -1


class MyQueue:

	def __init__(self):
		self.Queue = []
		self.pointer = -1

	def push(self, x):
		self.Queue.append(x)

	def pop(self):
		if self.pointer == len(self.Queue) - 1:
			return -1
		self.pointer += 1
		return self.Queue[self.pointer]


class MyQueue:

	def __init__(self):
		self.arr = []
		self.p = 0

	def push(self, x):
		self.arr.append(x)

	def pop(self):
		l = len(self.arr)
		if self.p < l:
			t = self.arr[self.p]
			self.p += 1
			return t
		return -1


class MyQueue:

	def __init__(self):
		self.arr = []
		self.front = -1
		self.rear = -1

	def push(self, x):
		self.arr.append(x)
		self.rear += 1

	def pop(self):
		if self.front == self.rear:
			return -1
		else:
			self.front += 1
			return self.arr[self.front]