Data Structures & AlgorithmsHardProduct placement · Amazon/Microsoft
Evaluate the postfix expression 7 4 − 2 + 6 − 8 × 7 1 + + (all divisions are exact). What is its value, and what is the maximum number of operands on the stack at any moment?
- A. 0; 4
- B. 64; 3
- C. 0; 3
- D. 64; 2
Correct answer: C. 0; 3
On each operator pop b (top) then a, and push a op b — the first popped value is the RIGHT operand. Tracing gives 0, with the stack peaking at 3 values. Swapping the operand order gives 64.
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
- KMP failure function (lps[i] = length of the longest proper prefix of p[0..i] that is also a suffix). What is printed? python def lps(p)…
- A sorted array was rotated to give [58, 67, 70, 71, 77, 3, 12, 14, 55]. Binary search finds the index of the minimum: while lo < hi, mid =…
- A string s has length n. What is the time complexity of building s by repeated concatenation s = s + c in a language with immutable…
- What does this loop-counting code print? (Python) python n, c = 10, 0 for i in range(n): for j in range(i + 1, n): for k in range(j + 1…
- Over all left rotations of [5, 1, 5, 3, 9, 4], what is the maximum value of Σ i·a[i] (0-based)? (Use R(j) = R(j − 1) + sum − n·a[n − j] to…
- Items K, L, M, N, O, P are pushed onto an empty stack in this order, and a pop may happen at any time. Which pop order is NOT possible?