Data Structures & AlgorithmsHardTCS NQT · Accenture
A singly linked list holds 1, 2, 3, 4, 5, 6, 7. Adjacent pairs are swapped in one pass (node 1 with 2, node 3 with 4, and so on; an unpaired last node stays). What value is at position 4 of the result (1-based)?
- A. 2
- B. 4
- C. 6
- D. 3
Correct answer: D. 3
Swapping pairs gives 2 1 4 3 6 5 7, so position 4 holds 3. Swapping the data inside nodes versus relinking nodes gives the same values here.
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 index pairs i < j in the array [1, 2, 3, 1, 2, 3] make a[i] a[j] = 6?
- How many contiguous subarrays of [2, -2, 3, 1, -4, 2, -1] have sum 0?
- How many index pairs i < j in the array [1, 3, 5, 7, 2, 6, 8] have a[i] + a[j] equal to a power of 2?
- The string (()(()(( is scanned left to right: '(' opens and ')' closes the most recent unmatched '('. How many characters are unmatched in…
- What is the minimum number of brackets that must be inserted into ())(()(( to make it a balanced sequence?
- What is the length of the longest valid (well-formed) parentheses substring of )()())?