Data Structures & AlgorithmsVery hardGATE CS · TCS NQT
A list holds 1 to 9 in order. The first 4 nodes are reversed, then the node with value 6 is deleted. What is the value at position 5 of the resulting list (1-based)?
- A. 6
- B. 7
- C. 9
- D. 5
Correct answer: D. 5
After reversing the first four nodes the list is 4, 3, 2, 1, 5, 6, 7, 8, 9; deleting 6 leaves 4, 3, 2, 1, 5, 7, 8, 9, so position 5 holds 5.
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, 3, -3, 2, 1] have sum exactly zero?
- How many index pairs i < j in [1, 3, 5, 7, 9, 4] have |a[i] - a[j]| = 2?
- How many distinct values appear among the XORs of all non-empty contiguous subarrays of [1, 2, 3]?
- How many windows of length 3 in the string abaaabaa are anagrams of aab (same letters with the same counts)?
- What is the length of the longest substring of aabaaccaa that contains at most two letters 'a'?
- How many palindromic substrings (counted by position) does the string abbaabba contain?