Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA
Evaluate the postfix expression "3 4 min 5 max 2 +" where min and max take two operands and return the smaller or larger.
- A. 8
- B. 6
- C. 7
- D. 14
Correct answer: C. 7
Process tokens left to right with a stack: 3 and 4 give min 3, which is pushed; 5 then gives max(3, 5) = 5; the final 2 is added to 5 to give 7.
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
- What is the length of the longest contiguous subarray of [2, 0, 0, 2, 0, 2, 2] whose sum is 0?
- How many integers from 1 to 100 inclusive are divisible by none of 2, 3 and 5?
- What is the digital root of the product 9 18 27 34?
- Which string is the longest common prefix of ["flower", "flow", "flight", "flute", "fly"]?
- Items (value, weight) = (60, 10), (100, 20), (120, 30) can be split fractionally. With capacity 50, what is the maximum total value?
- How many windows of size 3 in [1, 2, 2, 3, 4, 4, 5] have every pair of adjacent elements inside the window different?