0
0
DSA Pythonprogramming~10 mins

Double Ended Queue Deque in DSA Python - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create an empty deque using Python's collections module.

DSA Python
from collections import deque

my_deque = deque([1])
print(my_deque)
Drag options to blanks, or click blank then click option'
ANone
B[]
C{}
D()
Attempts:
3 left
💡 Hint
Common Mistakes
Passing None which causes error
2fill in blank
medium

Complete the code to add an element 10 to the right end of the deque.

DSA Python
from collections import deque

my_deque = deque([])
my_deque.[1](10)
print(my_deque)
Drag options to blanks, or click blank then click option'
Aappendleft
Bpop
Cpopleft
Dappend
Attempts:
3 left
💡 Hint
Common Mistakes
Using pop or popleft which remove elements
Using appendleft which adds to the left end
3fill in blank
hard

Fix the error in the code to remove an element from the left end of the deque.

DSA Python
from collections import deque

my_deque = deque([1, 2, 3])
removed = my_deque.[1]()
print(removed)
print(my_deque)
Drag options to blanks, or click blank then click option'
Apopleft
Bremove
Cpop
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using pop which removes from right end
Using remove which removes by value, not position
Using delete which is not a deque method
4fill in blank
hard

Fill both blanks to rotate the deque one step to the right.

DSA Python
from collections import deque

my_deque = deque([1, 2, 3, 4])
my_deque.[1]([2])
print(my_deque)
Drag options to blanks, or click blank then click option'
Arotate
Bappend
C1
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Using append instead of rotate
Using negative number to rotate right
5fill in blank
hard

Fill all three blanks to create a deque, add 5 to the left, and remove from the right.

DSA Python
from collections import deque

my_deque = deque([1])
my_deque.[2](5)
removed = my_deque.[3]()
print(removed)
print(my_deque)
Drag options to blanks, or click blank then click option'
A[]
Bappendleft
Cpop
D[1, 2, 3]
Attempts:
3 left
💡 Hint
Common Mistakes
Starting with empty deque instead of list
Using append instead of appendleft
Using popleft instead of pop