Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: Start with the empty stack. Process the string "7 3 * 2 + 5 -" as postfix tokens (numbers are pushed, operators pop two values, compute second-from-top op top). What is the result?
- A. 18
- B. 14
- C. 23
- D. 30
Correct answer: A. 18
Postfix: 7 3 * → 21, 21 2 + → 23, 23 5 - → 18 (second-from-top minus top). Reading it as 21 − (2 + 5) gives 14, stopping before the last operator leaves 23, and doing + before * gives 7 × 5 − 5 = 30.
More Coding Interview Problems questions
- Problem: The circular array [3, 1, 4, 2] has a 'next' pointer from each index i to (i+1) mod 4. Starting at index 0 and jumping by the…
- Problem: A stack of plates is filled by pushing 1 to 6 in order and popping after each push whenever the top is even. The final stack…
- Problem: A grid of 4×4 cells holds the value r + c (0-indexed). Starting from the top-left corner, what is the maximum total of values…
- Problem: A string is compressed by replacing each maximal run of equal letters with the letter and its count, only when the count is at…
- Problem: Pancake sort uses only prefix reversals on [3, 1, 2]. For each size from n down to 2, bring the largest value of the unsorted…
- Problem: In the array [2, 7, 11, 15, 3, 8], how many pairs i < j have a[i] + a[j] equal to a multiple of 5?