Data Structures & AlgorithmsHardGATE CS · TCS NQT · Product Company SDE
Evaluate the postfix expression: 4 3 * 7 + 1 -
- A. -18
- B. 17
- C. 18
- D. 19
Correct answer: C. 18
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 18.
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
- A circular queue is implemented in an array of size 9 with front = 1 and rear = 8 (rear indexes the last stored element, the queue is…
- Quicksort with Lomuto partitioning (last element as pivot) sorts [12, 42, 92, 73, 37, 39, 75, 75, 32]. How many swaps happen in total…
- A singly linked list is 95 -> 83 -> 36 -> 42 -> 99 -> 64 -> 72 -> None. The first 5 nodes are reversed in place (the node that was…
- Using a monotonic (increasing) stack to find, for each element of [20, 17, 18, 14, 44, 28], the nearest element to its left that is…
- A monotonic decreasing stack of indices is used to compute the next-greater-element array for [48, 12, 29, 6, 30, 28] (push index i after…
- A singly linked list is 47 -> 24 -> 78 -> 79 -> 98 -> 29 -> 13 -> None. The standard iterative in-place reversal (prev = None; while cur…