Data Structures & AlgorithmsVery hardGATE CS
A singly linked list holds 1, 2, ..., 11 in order. Starting from the head, every alternate group of k = 3 consecutive nodes is reversed in place (the 1st, 3rd and 5th groups are reversed; the 2nd and 4th are left as they are; the last group has fewer than 3 nodes). What is the value stored in the 9th node of the resulting list?
- A. 7
- B. 9
- C. 8
- D. 10
Correct answer: A. 7
Groups: (1,2,3) reversed, (4,5,6) kept, (7,8,9) reversed, (10,11) is the 4th group and is kept, giving [3, 2, 1, 4, 5, 6, 9, 8, 7, 10, 11]. Hence the 9th node holds 7.
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
- For the array [7, 2, 4, 9, 3, 5, 1, 8, 6, 2, 10, 4, 3, 9] and window size k = 4, compute (maximum - minimum) for every window of k…
- The span of a day is the number of consecutive days ending that day (including it) whose price is at most that day's price. For prices…
- Bars of unit width have heights [3, 0, 2, 0, 4, 0, 1, 3, 0, 2, 5, 1, 0, 3]. After rain, how many units of water are trapped between the…
- For the array [3, 1, 2, 4, 1, 5, 2, 6], what is the sum of the minimum element over all contiguous subarrays?
- How many non-empty contiguous subarrays of [5, 2, -3, 8, 6, -9, 4, 7, 1, 3, 12, -5, 6, 2] have a sum divisible by 7?
- The infix expression ab^c^d-(e+fg)^h/i+j (^ is right-associative with highest precedence, then and /, then + and -, all others…