Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS
How many different output orders can a stack produce from the input 1, 2, 3, 4 pushed in order?
- A. 24
- B. 16
- C. 10
- D. 14
Correct answer: D. 14
The number of stack-generated permutations of n items is the Catalan number C_n, and C_4 = 14. All 24 permutations are not reachable with a single stack.
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
- In "abccbaxyz", take the longest palindromic substring (the first one if tied) and count its distinct characters.
- In "abcdbefg", what is the 0-based index of the first character that repeats an earlier character?
- How many integers from 1 to 60 inclusive are multiples of 3 or of 4 but not of 12?
- What is the length of the longest common prefix of "interview", "internet" and "interval"?
- What is the smallest positive integer x such that x^2 + x is at least 1000?
- How many index pairs i < j in [1, 4, 6, 3, 2] satisfy a[i] XOR a[j] < min(a[i], a[j])?