🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Stack & Queue Quiz: all 8 questions

Stack & Queue Quiz · Question 8 of 8

Which Python structure should you use as a queue?

Which Python structure should you use as a queue?

  1. A.list with pop(0)
  2. B.collections.deque with popleft()
  3. C.set
  4. D.dict
Answer & explanation

Correct answer: collections.deque with popleft()

list.pop(0) shifts every element (O(n)); deque.popleft() is O(1).

Can you get the rest right without peeking?

Take the timed Stack & Queue Quiz quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →