Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys
Problem: A stack starts with the characters pushed in the order a, b, c, d. The following pops occur: pop, pop, then push e, pop. Which character is at the top of the stack at the end?
- A. a
- B. c
- C. d
- D. b
Correct answer: D. b
After popping d and c the stack holds a, b; pushing e and popping it leaves b on top. Mistaking the top for the first pushed item gives a.
More Coding Interview Problems questions
- Problem: The grid 2×3 contains the values [[1,2,3],[4,5,6]]. From the top-left cell you move right or down to the bottom-right, collecting…
- Problem: The sum of the digits of 2^15 is what value?
- Problem: How many subarrays of [2, 4, 1, 3, 6, 5] have an even sum? Run the code. python a = [2, 4, 1, 3, 6, 5] print(sum(1 for i in…
- Problem: How many integers x in [1, 999] satisfy x ≡ 2 (mod 3) and x ≡ 5 (mod 7)? Run the code. python print(sum(1 for x in range(1, 1000)…
- Problem: How many squares (k k with k >= 1) are at most 10^6? Run the code. python print(sum(1 for k in range(1, 10 6) if k k <= 10 6))…
- Problem: What is the maximum value of x (100 - x) over integers 0 <= x <= 100? Run the code. python print(max(x (100 - x) for x in…