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.
- A. [4, 9, 5, 8]
- B. [9, 5, 8]
- C. [9, 5, 8, 1]
- 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
- Problem: How many integers x in the range 1 ≤ x ≤ 1000 have exactly 4 set bits in their binary representation?
- Problem: A staircase can be climbed by steps of size 1, 3 or 4. How many distinct ordered sequences of steps climb exactly 13 stairs?
- Problem: What is the length of the longest strictly increasing subsequence of the sequence 10, 9, 2, 5, 3, 7, 101, 18, 4, 6, 8, 1, 12?
- Problem: Coins of denominations 5, 12 and 20 are available in unlimited supply. What is the minimum number of coins needed to make exactly…
- Problem: The list [25, 14, 9, 31, 7, 18, 3, 12] is turned into a min-heap in place with heapify (standard bottom-up sift-down, 0-indexed)…
- Problem: The sorted array [2, 4, 4, 4, 7, 9, 9, 12] is searched with bisectleft and bisectright. What is bisectright(a, 4) − bisectleft(a…