Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: Evaluate the postfix expression "3 4 + 2 * 7 −" using a stack (the operator pops the top two values, computes second-from-top op top). What is the result?
- A. 7
- B. -7
- C. 4
- D. 14
Correct answer: A. 7
3 4 + leaves 7, 2 * leaves 14, and 7 − computes second-from-top minus top = 14 − 7 = 7. Popping in the wrong order gives 7 − 14 = −7, reading the tokens as infix 3 + 4 × 2 − 7 gives 4, and stopping before the last operator leaves 14.
More Coding Interview Problems questions
- Problem: Rule 30 cellular automaton on an infinite line starts with a single live cell. Each generation, a cell's new state is determined…
- Problem: How many integers x with 1 ≤ x ≤ 100 have an odd number of set bits in their binary representation AND are odd themselves?
- Problem: What is the minimum number of bit flips needed to convert 29 into 15 (flips of single bits in binary)?
- Problem: What is the largest power of 2 that divides 480 × 36?
- Problem: How many pairs (a, b) with 1 ≤ a < b ≤ 20 satisfy gcd(a, b) = 1?
- Problem: Find the last digit (units digit) of 7^(7^7) in decimal.