Data Structures & AlgorithmsModerateTCS NQT · Infosys

Problem: A deque starts empty. Operations in order: push_back(5), push_front(2), push_back(8), pop_front(), push_front(9), push_back(1), pop_back(), push_front(4), pop_front(). Output the remaining deque from front to back as a list of integers.

  1. A. [4, 9, 5, 8]
  2. B. [9, 5, 8]
  3. C. [9, 5, 8, 1]
  4. D. [5, 8, 1]

Correct answer: B. [9, 5, 8]

Track each operation on both ends: the final front-to-back contents are 9, 5, 8. Forgetting one of the pops, or treating the deque as a stack, gives a different list.

More Coding Interview Problems questions

Exams that ask this topic