ProgrammingModerateAmazon OA · Flipkart coding round

What is the time complexity of `x in d` where d is a collections.deque of n items?

  1. A. O(log n), because a deque is kept sorted
  2. B. O(n log n), because the deque is sorted before the search
  3. C. O(n), because deque membership scans the items one by one
  4. D. O(1), because a deque is a hash table

Correct answer: C. O(n), because deque membership scans the items one by one

A deque is a doubly linked block structure with no hash index, so membership scans in O(n). For fast membership use a set or dict.

More Python Programming questions

Exams that ask this topic