Data Structures & AlgorithmsModerateWipro · Accenture pattern
What is the value of the prefix expression + * 3 4 − 9 / 8 2 ?
- A. 17
- B. 12
- C. 8
- D. 21
Correct answer: A. 17
Scan right to left with a stack (the first popped value is the LEFT operand): 8 / 2 = 4; 9 − 4 = 5; 3 * 4 = 12; 12 + 5 = 17. Taking the first popped value as the RIGHT operand instead turns 9 − 4 into 4 − 9 and 8 / 2 into 2 / 8, which derails the result.
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
- Selection sort (find the minimum of the unsorted part, swap it to the front only if it is not already there) sorts [29, 10, 14, 37, 13]…
- Binary search with mid = (lo + hi) / 2 (integer division) looks for 31 in [3, 9, 14, 20, 27, 31, 40] (0-based). Which indices are probed…
- Starting from an empty stack: push 5, push 3, pop, push 8, push 2, pop, pop, push 7, push 1. What are the stack contents from top to bottom?
- A circular queue uses an array of size 5 (indices 0–4); front is the index of the first element and rear is the index of the last element…
- Double hashing in a table of size 11 uses h1(k) = k mod 11 and h2(k) = 7 − (k mod 7); probe i goes to (h1 + i·h2) mod 11. Keys 14, 25, 36…
- How many DISTINCT palindromic substrings (counted as strings, not by position) does 'abaab' have?