Data Structures & AlgorithmsHardGATE CS · TCS NQT
Given the linked list 1 -> 2 -> ... -> 8, the list is reversed in consecutive groups of 3 (a final group with fewer than 3 nodes is left unchanged). What is the value of the 7th node?
- A. 8
- B. 7
- C. 4
- D. 6
Correct answer: B. 7
Groups become [3,2,1], [6,5,4] and [7,8]. The final short group must stay in order, so reversing it wrongly changes the 7th node.
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
- A linked list has a tail of 3 nodes leading into a cycle of 5 nodes. A slow pointer advances 1 node per step and a fast pointer advances 2…
- How many index pairs i < j satisfy (a[i] + a[j]) mod 7 = 0 for the array [3, 4, 7, 10, 11, 14, 21, 5, 9]?
- How many index pairs i < j satisfy a[i] XOR a[j] = 6 for the array [1, 4, 7, 2, 5, 3, 6]?
- How many contiguous subarrays of [3, -1, 2, -2, 4, -3, 1] have sum exactly 2?
- What is the length of the longest contiguous substring of the binary string 1100101101 that contains equal numbers of 0s and 1s?
- How many index pairs i < j make a[i] times a[j] a perfect square, for the array [2, 8, 18, 5, 12, 9, 50, 25, 32]?