Data Structures & AlgorithmsHardCodeforces Div2 B-D · ICPC regional
A linked list holds 1..8 in order. Reverse the first group of 2 nodes, keep the next group of 2 as is, reverse the next, and so on. What is the resulting order?
- A. 2 1 3 4 6 5 7 8
- B. 2 1 4 3 6 5 8 7
- C. 2 1 3 4 5 6 7 8
- D. 1 2 4 3 5 6 8 7
Correct answer: A. 2 1 3 4 6 5 7 8
Reverse the groups at even group indices only. Reversing every group (the standard k-group reversal) gives a different order.
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
- Exactly how many permutations of 1..5 can be sorted by a single stack (push and pop operations, output must be 1, 2, 3, 4, 5)?
- A queue holds 3, 1, 4, 2, 5 from front to back. You repeatedly look at the front element: if it is the next value needed (starting with…
- For windows of size 3 over [3, 1, 4, 2, 5, 1, 6, 0], how many windows have their maximum at the last position of the window (ties count as…
- Four unit-time jobs given as (deadline, profit) are (4, 20), (1, 10), (1, 40), (1, 30). Each job must finish by its deadline and only one…
- What is the length of the shortest contiguous subarray which, if sorted in place, makes the whole array [2, 6, 4, 8, 10, 9, 15] sorted?
- What is the number of trailing zeros in the decimal representation of the product 10 25 4 15 50?