Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div2 D
Problem: A stack-sortable check is applied to the permutation [3, 1, 2]: elements are pushed in order and popped whenever the top equals the next expected value (1, 2, 3, …). Is the stack empty at the end? Answer 1 for yes, 0 for no.
- A. 2
- B. 1
- C. 0
- D. 3
Correct answer: B. 1
Push 3, then 1 is pushed and popped, then 2 is pushed and popped, which releases 3 from the stack. The stack is empty at the end, so the permutation is stack-sortable.
More Coding Interview Problems questions
- Problem: The array [5, 2, 8, 2, 9, 1, 5, 5] contains repeated values. How many distinct values appear exactly twice?
- Problem: What is the maximum sum of a subsequence of [4, −1, 2, 1] with no two adjacent elements chosen (the empty selection is not…
- Problem: The string "ABCABCABC" is read and each letter is replaced by its position in the alphabet (A=1, B=2, C=3). What is the sum of…
- Problem: From the list [12, 18, 24, 30, 36], what is the number of distinct prime divisors of the product of all five numbers?
- Problem: The array [7, 1, 5, 3, 6, 4] is processed to find the maximum profit from one buy and one later sell (0 if none). What is the…
- Problem: A grid of 3×3 cells is numbered 1 to 9 row by row. Starting at 1 (top-left), the robot moves right or down. The number of paths…