Data Structures & AlgorithmsModerateTCS NQT · Infosys
Problem: A deque starts as [2, 4, 6]. The operations are: push front 1, push back 8, pop front, push back 3. What is the sum of the final deque?
- A. 23
- B. 24
- C. 16
- D. 12
Correct answer: A. 23
[2,4,6] → [1,2,4,6] → [1,2,4,6,8] → pop front → [2,4,6,8] → [2,4,6,8,3], sum 23. Skipping the pop gives 24, popping from the back instead gives 16, and 12 is the untouched starting sum.
More Coding Interview Problems questions
- Problem: The string "tenet" is considered. How many of its substrings (by index range, length at least 2) are palindromes?
- Problem: Water fills a 1-dimensional container with walls of heights [4, 1, 3, 1, 2]. Each cell holds water up to the minimum of the…
- Problem: Compute the sum of all integers from 1 to 999 whose digits are all odd.
- Problem: What is the number of ways to climb 8 steps when each move is 1, 2 or 4 steps, counted as ordered sequences?
- Problem: The array [1, 2, 3, 4, 5, 6, 7, 8, 9] is split into 3 consecutive groups of equal length. What is the sum of the middle group?
- Problem: The product of the numbers from 1 to 10, divided by the product of the numbers from 1 to 7, is what value?