Data Structures & AlgorithmsHardGATE CS · TCS NQT
The nodes of the list 1, 2, 3, 4, 5, 6, 7, 8 are rearranged into all odd-position nodes followed by all even-position nodes (1-based positions, order kept). What value is at position 5 of the new list?
- A. 3
- B. {C-1}
- C. 4
- D. 2
Correct answer: D. 2
The new order is 1, 3, 5, 7, 2, 4, 6, 8, so position 5 holds 2. Mistaking the odd positions for the even ones gives a different sequence.
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 contiguous subarrays of [1, 2, 3, 4, 5, 6, 7] contain exactly 2 odd numbers?
- How many index pairs i < j in [1, 2, 3, 4, 5] have a[i] XOR a[j] equal to a power of two?
- How many index triples i < j < k in the array [1, 2, 3, 4, 5, 6] have a[i] + a[j] + a[k] = 10?
- How many values in [4, 4, 5, 6, 6, 7, 8] occur exactly once in the array?
- How many contiguous subarrays of [1, 1, 2, 2, 2, 3] contain only one distinct value?
- How many index pairs i < j in [1, 4, 7, 2, 5, 8] satisfy that a[i] - a[j] is divisible by 3?