Data Structures & AlgorithmsModerateCodeforces Div2 B-D · ICPC regional
Numbers 1, 2, 3, 4 are pushed in this order onto a stack. Can the pop sequence 3, 4, 2, 1 be produced?
- A. yes
- B. no, because 2 must be popped before 3
- C. yes, but only with a second stack
- D. no, because the stack holds at most two items
Correct answer: A. yes
Push 1, 2 and 3 and pop 3; push 4 and pop 4; the stack top is then 2, and 2 then 1 come off in order. The sequence is valid.
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
- How many length-3 substrings of "abcabc" are rotations of "abc" (namely abc, bca or cab)?
- What is the sum of the decimal digits of 2^20?
- Among intervals [1,6], [4,9], [5,5], [2,8], [5,7], [3,6] that contain the point 5, what is the largest number that are pairwise disjoint…
- How many index pairs i < j in [2, 3, 4, 5, 8, 9] have an odd sum?
- How many integers from 1 to 999 inclusive have all decimal digits distinct?
- Using coins of value 5, 2 and 1, what is the minimum number of coins that make the amount 11?