Data Structures & AlgorithmsHardTCS NQT · Infosys
Evaluate the postfix (reverse Polish) expression 5 1 2 + 4 * + 3 -. What is the value?
- A. 15
- B. 14
- C. 12
- D. 18
Correct answer: B. 14
Operands are pushed on a stack and each operator pops the top two, with the second popped value as the left operand. Reversing the order of the operands for subtraction gives the wrong sign.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- Array [5, 2, 8, 1, 9, 3] is processed in one left-to-right pass: each node is deleted if its value is strictly greater than the value of…
- A singly linked list holds 1, 2, 3, 4, 5, 6, 7. Adjacent pairs are swapped in one pass (node 1 with 2, node 3 with 4, and so on; an…
- How many index pairs i < j in the array [1, 2, 3, 1, 2, 3] make a[i] a[j] = 6?
- How many contiguous subarrays of [2, -2, 3, 1, -4, 2, -1] have sum 0?
- How many index pairs i < j in the array [1, 3, 5, 7, 2, 6, 8] have a[i] + a[j] equal to a power of 2?
- The string (()(()(( is scanned left to right: '(' opens and ')' closes the most recent unmatched '('. How many characters are unmatched in…