Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: A stack-based simulation begins with an empty stack. Operations in order: push 4, push 7, push 2, pop, push 9, pop, push 5. What is the sum of the values remaining on the stack, read from bottom to top?
- A. 27
- B. 25
- C. 11
- D. 16
Correct answer: D. 16
After push 4, 7, 2, pop (2), push 9, pop (9), push 5 the stack holds 4, 7, 5, sum 16. Ignoring the pops gives 27, missing the second pop gives 25, and missing the final push gives 11.
More Coding Interview Problems questions
- Problem: A tree on 5 nodes is given by edges 1-2, 2-3, 2-4, 4-5. The diameter (in edges) of this tree is what value?
- Problem: A sequence is defined by s(1) = 1, s(2) = 2, and s(n) = s(n−1) + s(n−2) for n ≥ 3. What is the remainder when s(12) is divided by…
- Problem: How many subsets of {1, 2, 3, 4, 5, 6} contain exactly two odd numbers?
- Problem: The product of the first 6 positive odd numbers 1·3·5·7·9·11 is computed. What is that product's value modulo 100?
- Problem: A cyclic array [1, 2, 3, 4, 5] is rotated so that the element at index 0 becomes the element at index 2 (rotate left by 2). What…
- Problem: Starting from 5 on a number line, you may jump +2 or +3 each turn and must land exactly on 25. How many distinct jump sequences…