Data Structures & AlgorithmsHardGATE CS · TCS NQT · Product Company SDE
Evaluate the postfix expression: 1 1 - 5 - 5 -
- A. -9
- B. -10
- C. -11
- D. 10
Correct answer: B. -10
Scan left to right with a stack: push operands, and on an operator pop b then a and push a op b, preserving operand order (important for - and /). Result -10.
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
- Heap sort (build a max-heap, then repeatedly swap the root with the last unsorted element and sift down) is run on [91, 96, 8, 20, 80, 10…
- Using a monotonic (decreasing) stack to find, for each element of [32, 3, 22, 30, 36, 26, 11, 9], the next element to its right that is…
- Quicksort uses the Lomuto partition with the last element as pivot on [42, 63, 77, 95, 70, 32, 1, 32, 76]. After one partition call, at…
- Evaluate the postfix expression: 5 9 + 4 2 +
- A function makes two recursive calls on an array of size n, each on a half of size n/2, and does O(n) extra work to combine the results…
- A singly linked list has nodes at positions 0..5 holding 74 -> 10 -> 74 -> 58 -> 91 -> 24, but the last node's next pointer points back to…