Data Structures & AlgorithmsHardProduct-company MCQ pattern
What is the postfix (Reverse Polish) form of the infix expression "(i + j)* d - b / h", built with the standard stack-based conversion (^ right-associative, others left-associative)?
- A. i j d b h / - * +
- B. i j + d * b h / -
- C. - / h b * d + j i
- D. i j + d * b - h /
Correct answer: B. i j + d * b h / -
Using a stack to hold pending operators and popping higher-or-equal precedence operators before pushing a new one (left-associative) gives "i j + d * b h / -". Treating all operators as equal precedence instead would wrongly give "i j + d * b - h /".
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 [61, 75, 77, 8, 27, 29, 31, 32, 47, 56] is a sorted array rotated at pivot 7. Using the standard O(log n) rotated-array binary…
- Using a sliding window (shrink from the left whenever more than k distinct characters are in the window), what is the length of the…
- Elevation map [2, 2, 5, 0, 2, 0, 3, 1, 1, 1] (bar width 1). Using the two-pointer / prefix-max approach for trapping rain water, how much…
- Using a sliding window of fixed size with a character-frequency count, how many substrings of "BAAAABBAACB" are anagrams of "AB"?
- A queue is implemented with two stacks (enqueue pushes to stack "in"; dequeue pops from stack "out", refilling "out" from "in" by…
- A queue is implemented with two stacks (enqueue pushes to stack "in"; dequeue pops from stack "out", refilling "out" from "in" by…