HackerRank Collections.deque() solution in python YASH PAL, 31 July 202417 January 2026 HackerRank Collections.deque() solution in python – In this Collections.deque() problem we need to develop a python program that can read integer and space separated methods on the next line. and we need to print the space-separated elements on the output screen.A deque is a double-ended queue. It can be used to add or remove elements from both ends.Deques support thread safe, memory efficient appends and pops from either side of the deque with approximately the same performance in either direction.Problem solution in Python 2 programming.# Enter your code here. Read input from STDIN. Print output to STDOUT from collections import deque d=deque() N=int(raw_input()) for i in range(N): A=list(raw_input().split()) if A[0]=='append': d.append(int(A[1])) elif A[0]=='appendleft': d.appendleft(int(A[1])) elif A[0]=='pop': d.pop() elif A[0]=='popleft': d.popleft() for i in d: print i,Problem solution in Python 3 programming.# Enter your code here. Read input from STDIN. Print output to STDOUT from collections import deque d = deque() for _ in range(int(input())): inp = input().split() getattr(d, inp[0])(*[inp[1]] if len(inp) > 1 else []) print(*[item for item in d])Problem solution in pypy programming.# Enter your code here. Read input from STDIN. Print output to STDOUT from collections import deque d = deque() for i in range(input()): eval('d.{0}({1})'.format(*raw_input().split()+[''])) print ' '.join(map(str,d)) Problem solution in pypy3 programming.# https://www.hackerrank.com/challenges/py-collections-deque?h_r=next-challenge&h_v=zen from collections import deque d = deque() for i in range(int(input())): operation, *number = input().split() if number: num1 = int(number[0]) if operation == 'append': d.append(num1) elif operation == 'appendleft': d.appendleft(num1) elif operation == 'pop': d.pop() elif operation == 'popleft': d.popleft() for i in range(len(d)): print(d.popleft(), end = ' ') coding problems solutions Hackerrank Problems Solutions Python Solutions HackerRankPython