Data Structures & AlgorithmsVery hard
A linked list holds 1 through 10 in order. Going from the head, reverse the first 3 nodes, leave the next 3 unchanged, reverse the next 3, leave the next 3, and so on; a final partial group is treated the same way. Give the final sequence.
- A. 2 1 3 4 6 5 7 8 10 9
- B. 10 9 8 7 6 5 4 3 2 1
- C. 3 2 1 4 5 6 9 8 7 10
- D. 1 2 3 6 5 4 7 8 9 10
Correct answer: C. 3 2 1 4 5 6 9 8 7 10
Reverse each block of length k at positions 0, 2k, 4k … in place, and leave the blocks in between unchanged. Using a different block size or reversing the whole list changes the output.
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 pairs of positions i < j in the array 12 21 3 30 111 24 42 have DIGIT SUMS that are equal?
- In the string "((a)(b(c)))d((e))", what is the maximum nesting depth of round brackets (the number of brackets open at the deepest point)?
- How many contiguous subarrays of 1 4 2 6 3 5 have an AVERAGE that is at least 3?
- What is the maximum sum of a contiguous subarray of -3 4 -1 2 5 -6 3 1 whose LENGTH is between 2 and 3 inclusive?
- How many contiguous subarrays of 5 1 9 4 8 3 7 have (maximum − minimum) at least 3?
- What is the length of the shortest contiguous subarray of 2 1 2 3 1 3 2 1 that contains EVERY distinct value appearing in the array?